How to refresh a ListView to requery its cursor to repopulate its data and its views

后端 未结 4 829
孤街浪徒
孤街浪徒 2021-01-12 04:03

I have a ListView which uses a CursorAdatper as its adapter. I would like to have the list view to

  • requery its data
  • refresh its view once the requery
相关标签:
4条回答
  • 2021-01-12 04:27

    you can try: adapter.changeCursor(new cursor). It work for me

    0 讨论(0)
  • 2021-01-12 04:32

    I know this answer is probably too late but fyi to others, if you are using a cursor loader (as you probably should do instead), just do

    getContext().getContentResolver().notifyChange(uri, null);

    where uri is the same uri used for the cursor loader.

    0 讨论(0)
  • 2021-01-12 04:36

    Calling requery() on a database or content provider Cursor attached to ListView via a CursorAdapter automatically refreshes the list (your second scenario above). You can see some examples of this. If that is not working for you, there may be some bug in your ContentProvider or adapter.

    0 讨论(0)
  • 2021-01-12 04:52

    In the new API (using loader manager) you can use:

    getLoaderManager().getLoader(_YOUR_LOADER_ID_).forceLoad();
    
    0 讨论(0)
提交回复
热议问题