ArrayAdapter.setNotifyOnChange 无法正常工作

发布于 2024-11-25 11:21:36 字数 1237 浏览 1 评论 0原文

我想控制 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美不过初阳 2024-12-02 11:21:36

您是否尝试过adapter.notifyDataSetChanged()而不是notifyDataSetChanged()?

have you tried adapter.notifyDataSetChanged() instead of notifyDataSetChanged()?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文