如何在BaseAdapter中更新自定义变量?

时间:2014-11-11 02:48:15

标签: android baseadapter notifydatasetchanged

在Android中,我写了一个类

public class ImageAdapter extends BaseAdapter {

    private Context context;
    private Cursor imageCursor;

    public ImageAdapter(Context context, Cursor imageCursor) {
        this.context = context;
        this.imageCursor = imageCursor;
    }
}

在这段代码中,我想在调用notifyDataSetChanged()方法时更新 imageCursor 变量的值。 我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

您可以覆盖notifyDatasetChanged()并在调用super.notifyDatasetChanged之前放置代码,或者创建这样的自定义方法,

public void updateNotifyDatasetChanged(Cursor newImageCursor){
    this.imageCursor = newImageCursor;
    notifyDatasetChanged();
}