0

我正在尝试从数组中加载一些图像,以下是我的计划适配器。只是得到未定义的上下文。不知道该怎么办 ?也没有加载图像

public class Schedule_ArrayAdapter extends ArrayAdapter<String> {
private final Activity activity;
private final String[] name, category, image;
Typeface colab, colab_bold, Bebas;
int selected = -1;

public Schedule_ArrayAdapter(Activity activity, String[] name, String[] category, String[] image) {
    super(activity, R.layout.schedule_item, category);
    this.activity = activity;
    this.name = name;
    this.category = category;
    this.image = image;

    this.colab = Typeface.createFromAsset(activity.getAssets(), "ColabThi.otf");
    this.colab_bold = Typeface.createFromAsset(activity.getAssets(), "ColabMed.otf");
    this.colab_bold = Typeface.createFromAsset(activity.getAssets(), "BebasNeue.otf");
//  ImageLoader.getInstance().init(config);
    imageLoader = ImageLoader.getInstance();
}

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
    .memoryCache(new WeakMemoryCache())
    .denyCacheImageMultipleSizesInMemory()
    .threadPoolSize(5)
    .enableLogging()
    .build();

    DisplayImageOptions options = new DisplayImageOptions.Builder()
    .cacheOnDisc()
    .cacheInMemory()
    .build();

    ImageLoader imageLoader= ImageLoader.getInstance();
4

1 回答 1

3

只需使用activity.getApplicationContext()而不是getApplicationContext()

您当前的类继承自 ArrayAdapter,它不是 Context 的子类。该getApplicationContext()方法仅在从 Context 继承的类中可用,Activities例如ServicesBroadcastReceivers

于 2013-05-19T03:11:28.083 回答