Android baseAdapter类中的上下文
有没有一种方法可以通过Android baseAdapter类中的上下文,android,baseadapter,android-context,Android,Baseadapter,Android Context,有没有一种方法可以通过getApplicationContext()在BaseAdapter类中获取context 我需要这个,因为我要从url加载图像。这里我使用的是上下文: 这是在扩展BaseAdapter ImageLoader imgLoader = new ImageLoader(getApplicationContext()); 扩展/实现时,将其传递到构造函数中: public class MyAdapter extends SomeBaseAdapter{ private
getApplicationContext()
在BaseAdapter
类中获取context
我需要这个,因为我要从url加载图像。这里我使用的是上下文
:
这是在扩展BaseAdapter
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
扩展/实现时,将其传递到构造函数中:
public class MyAdapter extends SomeBaseAdapter{
private final Context mcontext;
public MyAdapter(Context c){
mContext = c;
}
}
您可以在适配器构造函数中传递对上下文的引用并将其存储,也可以在方法
getView()
您可以尝试实例化一个变量,使上下文内容如下所示: 在getView()中 View-View=LayoutInflater.from(parent.getContext()).flate(R.layout.itemtutor,null) 并创建一个上下文变量:
Context mycontext=view.getContext() 在自定义BaseAdapter的构造函数中传递它您可以使用重载构造函数传递上下文
public class ToDoListAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//inflate layout
}
}