notificationDataSetChanged() 不更新列表视图

2023-12-20

我正在从我的后台方法更新我的列表视图:

 runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * Updating parsed JSON data into ListView
                 * */
                BaseAdapter adapter = new SimpleAdapter(
                        AllProductsActivity.this, productsList,
                        R.layout.list_item, new String[] { TAG_PID,
                                TAG_NAME},
                        new int[] { R.id.pid, R.id.name });
                // updating listview
                if(getListView().getAdapter() == null){ //Adapter not set yet.
                     setListAdapter(adapter);
                     Log.v("ha", "bla");
                }
                else
                { //Already has an adapter
                    adapter.notifyDataSetChanged();
                }
            }
        });

执行此代码:
- 第一次加载时
-滚动加载更多内容,我称之为adapter.notifyDataSetChanged(),但没有成功。

如何更新我的代码,以便我可以使用 notificationdatasetchanged 并将新数据添加到当前数据中。

我的整个代码:http://pastebin.com/cWmday3i http://pastebin.com/cWmday3i任何帮助表示赞赏。


您应该始终调用编写代码的方式setListAdapter,因为每次执行 runOnUiThread 内的 runnable 时,您都会创建一个新的 Adapter,可能会使用一个新的数据集。之间唯一的区别notifyDataSetChanged and NotifyDataSetChanged就是第二个不属于Android的API

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

notificationDataSetChanged() 不更新列表视图 的相关文章

随机推荐