Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Loader, why does restartLoader not refresh my Listview?
    primarykey
    data
    text
    <p>I am trying to do the following</p> <pre><code>1) Activity with a List view 2) Talks to content ContentProvider 3) Populates the ListView with contents of Cursor 4) User can then add new items to database 5) After each item is added I want to refresh the list view to show the updated items. </code></pre> <p>Everything upto point 5 works.</p> <p>So I need help with restarting the Loader after the item has been added.</p> <p>So after the data has been added to the database I am calling:</p> <blockquote> <p><code>getLoaderManager().restartLoader(ID, null, MyFragment.this);</code></p> </blockquote> <p>And in the Loader methods I simply do:</p> <pre><code>@Override public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) { Log.w(TAG, "onCreateLoader"); cursorLoader = new CursorLoader(getActivity(), MyContract.CONTENT_URI, null, null, null, "_id ASC"); return cursorLoader; } @Override public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor cursor) { adapter.swapCursor(cursor); //swap the new cursor in. } @Override public void onLoaderReset(Loader&lt;Cursor&gt; loader) { adapter.swapCursor(null); } </code></pre> <p>When this is called, the ListView blanks out. All previous items in the list disappear.</p> <p>If I go out of my activity and back into again the SimpleCursorAdapter will populate the ListView with the added items in the database. </p> <p>So I know they have been added correctly.</p> <p>But it is not displaying after I call restartLoader.</p> <p>Does anyone know how I can refresh the listView using the Loader ?</p> <p>Should I call something after </p> <pre><code>getLoaderManager().restartLoader(1, null, MyFragment.this);` </code></pre> <p>Or do I need to something more clever in onLoaderReset method ?</p> <p>Any tips and pointers please ?</p> <p>Thanks !!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload