如何获得上下文BaseAdapter Android中上下文、如何获得、Android、BaseAdapter

2023-09-05 02:16:43 作者:四字伤感名字,四字伤感游戏名字

我有一类名为 BinderData 延伸 BaseAdapter 。我想要得到的基类上下文。我试图用的getContext()但是,这并不如遇工作 BaseAdapter

I have a class named BinderData which extends BaseAdapter. I want to get the base class context. I tried to use getContext() but that doesn't work in case of BaseAdapter.

我怎样才能得到这个类的语境?

How can I get the Context of this class?

推荐答案

请一个构造函数一个上下文作为它的一个参数,并将其存储在私有变量。

Make a constructor that takes a Context as one of its arguments and store it in a private variable.

public class SampleAdapter extends BaseAdapter {
    private Context context;

    public SampleAdapter(Context context) {
        this.context = context;
    }

    /* ... other methods ... */
}