context
でBaseAdapter
クラスを取得する方法はありgetApplicationContext()
ますか?
URLから画像をロードするので、これが必要です。ここで私は使用していcontext
ます:
これは拡張されたクラスにありますBaseAdapter
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
context
でBaseAdapter
クラスを取得する方法はありgetApplicationContext()
ますか?
URLから画像をロードするので、これが必要です。ここで私は使用していcontext
ます:
これは拡張されたクラスにありますBaseAdapter
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
拡張/実装するときにコンストラクターで渡します。
public class MyAdapter extends SomeBaseAdapter{
private final Context mcontext;
public MyAdapter(Context c){
mContext = c;
}
}
アダプターコンストラクターでコンテキストへの参照を渡して保存するか、メソッドで親から直接参照することができますgetView()
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
}
}