ArrayAdapter.setNotifyOnChange 无法正常工作
我想控制 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();
}
该视图在我调用过滤操作之前显示。我在 ListActivity 中调用 adater.add() 方法,并且不在其他任何地方调用 notificationDataSetChanged() 。
我在这里转动我的轮子。我没有调试它的源代码。
当我调试时,当调用 arrayAdapter.getView 时,我可以看到 notificationdatasetchanged property=false 。有没有办法找出哪个事件正在调用它?
I want to control the display of my ListView data. I am filtering and sorting before I want to display the list. The list is being refreshed before I call publishResults() as well as after I do my filtering and call 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();
}
The view is displayed before I call the filter operation. I call adater.add() method inside my ListActivity and do not call notifyDataSetChanged() anywhere else.
I'm spinning my wheels here. I do not have the source to debug it.
When I debug I can see the notifydatasetchanged property=false when the arrayAdapter.getView is called. Is there a way to find out what event is calling this to be called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过adapter.notifyDataSetChanged()而不是notifyDataSetChanged()?
have you tried adapter.notifyDataSetChanged() instead of notifyDataSetChanged()?