2

contextBaseAdapterクラスを取得する方法はありgetApplicationContext()ますか?

URLから画像をロードするので、これが必要です。ここで私は使用していcontextます:

これは拡張されたクラスにありますBaseAdapter

ImageLoader imgLoader = new ImageLoader(getApplicationContext());
4

3 に答える 3

2

拡張/実装するときにコンストラクターで渡します。

public class MyAdapter extends SomeBaseAdapter{
  private final Context mcontext;

  public MyAdapter(Context c){
    mContext = c;
  }

}
于 2013-03-04T10:24:27.660 に答える
0

アダプターコンストラクターでコンテキストへの参照を渡して保存するか、メソッドで親から直接参照することができます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
    }
}
于 2015-03-17T16:49:42.310 に答える