开发者

android auto refresh listview item

开发者 https://www.devze.com 2023-04-03 18:29 出处:网络
First I setup a ListView adapter this.chapters = new ArrayList<String>(); ListView lvChapters = (ListView) findViewById(R.id.mangaChapterList);

First I setup a ListView adapter

this.chapters = new ArrayList<String>();
ListView lvChapters = (ListView) findViewById(R.id.mangaChapterList);
lvChapt开发者_如何学运维ers.setAdapter(new ChapterListAdapter(context, R.id.lvChapters, this.chapters));

After that, I popular some data into "this.chapters" in an AsyncTask class. But the listview still empty??


Show the code for your ChapterListAdapter, are you sure you are calling the registered observers?

If ChapterListAdapters is extending an ArrayAdapter, then you should call notifyDataSetChanged.

public void notifyDataSetChanged () Since: API Level 1

Notifies the attached View that the underlying data has been changed and it should refresh itself.


Reference your adapter through any variable like this

ChapterListAdapter adapter = new ChapterListAdapter(context, R.id.lvChapters, this.chapters);

and then set adapter.

pters.setAdapter(adapter);

and then just call adapter.notifyDataSetChanged(); after you add the data to the this.chapters.

0

精彩评论

暂无评论...
验证码 换一张
取 消