【发布时间】:2014-02-18 10:20:22
【问题描述】:
我看过许多示例/教程,这些示例/教程解释了如何更新BaseAdapter 使用的ArrayList。例如:
public class CustomAdapter extends BaseAdapter {
private ArrayList<Item> listData;
private LayoutInflater layoutInflater;
public CustomListAdapter(Context context, ArrayList<Item> listData) {
this.listData = listData;
layoutInflater = LayoutInflater.from(context);
}
//called to update the ListView
public void resetList(ArrayList<Item> newList) {
this.listData = newList;
this.notifyDataSetChanged();
}
}
另一种方法是清除并填充listData当前指向的原始ArrayList,并从Activity的线程中调用notifyDataSetChanged()。
为什么这是一种经常被推荐的方式?如果我在修改 ArrayList 之后或期间但在调用 notifyDataSetChanged() 之前直接单击 ListView 项目会发生什么?
【问题讨论】:
标签: java android arraylist listadapter