Android: how to refresh ListView contents?

后端 未结 9 925
渐次进展
渐次进展 2020-11-28 04:58

My ListView is using an extension of BaseAdapter, I can not get it to refresh properly. When I refresh, it appears that the old data draws on top

9条回答
  •  自闭症患者
    2020-11-28 05:44

    In my understanding, if you want to refresh ListView immediately when data has changed, you should call notifyDataSetChanged() in RunOnUiThread().

    private void updateData() {
        List newData = getYourNewData();
        mAdapter.setList(yourNewList);
    
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                    mAdapter.notifyDataSetChanged();
            }
        });
    }
    

提交回复
热议问题