如何获得上下文BaseAdapter Android中 [英] How to get context for BaseAdapter in Android
本文介绍了如何获得上下文BaseAdapter Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一类名为 BinderData code>延伸
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 ... */
}
这篇关于如何获得上下文BaseAdapter Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文