android - ArrayAdapter.setNotifyOnChange 工作不正常

标签 android listactivity android-arrayadapter

我想控制我的 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/

相关文章:

android - 尝试对自定义对象数组执行 readParcelable 时发生 ClassCastException

java - 如何在 RecyclerView 中准确显示 5 个项目

android - ListActivity 添加图片?

android - 如何使用 simple_list_item_multiple_choice 换行文本?

android - 微调器的数组适配器不能在 fragment 中工作,需要资源 ID

android - 无法清除 ArrayAdapter

android - 如何使用 Kotlin 在 Fragment 中使用 ArrayAdapter

java - 某些字符的正则表达式

android - 重新启动任务中的所有 Activity

mysql - SQL 查询从存储的表数据生成事件