我想控制我的 ListView 数据的显示。在我要显示列表之前,我正在过滤和排序。在我调用 publishResults() 之前以及在我进行过滤并调用 publishResults() 之后,列表正在刷新。
public StoreAdapter(Context context, int textViewResourceId, ArrayList<Store> items, StoresTab storeTab) {
super(context, textViewResourceId, items);
this.items = items;
this.storeTab = storeTab;
this.context = context;
this.filter = new StoreFilter();
imageLoader = ImageThreadLoader.getOnDiskInstance(context);
setNotifyOnChange(false);
}
protected void publishResults(CharSequence constraint, FilterResults results) {
// NOTE: this function is *always* called from the UI thread.
ArrayList<Store> filtered = (ArrayList<Store>)results.values;
clear();
if (filtered != null)
{
for (int i = 0; i < filtered.size(); i++)
{
add(filtered.get(i));
}
sort(storeTab);
}
notifyDataSetChanged();
}
View 在我调用筛选操作之前显示。我在我的 ListActivity 中调用了 adater.add() 方法,并且不在其他任何地方调用 notifyDataSetChanged()。
我在这里旋转我的轮子。我没有调试它的源代码。
当我调试时,我可以在调用 arrayAdapter.getView 时看到 notifydatasetchanged property=false。有没有办法找出调用此调用的事件?
最佳答案
你试过 adapter.notifyDataSetChanged() 而不是 notifyDataSetChanged() 吗?
关于android - ArrayAdapter.setNotifyOnChange 工作不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6796577/