Sunday, September 18, 2011

[android-developers] ListFragment items not refreshed in view, but db, and adapter are updated.

I just moved to Fragments a few weeks ago and I've enjoyed allot of
neat benefits like the PageView for my sorting filters on my main
listfragment.


For some reason on my ListFragment when I restartLoader to "requery"
the new data in the Cursor (which is the correct data) and I call
swapCursor on my CursorAdapter with the new data in onLoadFinished,
but for some reason i need to leave the activity or swipe to a new
page in the pageview (sometimes at least 2 pages away) and then return
to see the new updates in the list (like a checked item, or removed
items).

when i swipe to the next page using the pageview it's the same
listfragement (with a different sort) the data is correct.


before I used fragements I was using the cursoradapter and just called
requery as needed. now I have the same cursoradapter, but i also use a
Loader to create and swapCursor on the adapter.

some example of the listfragment code


public void restartLoader()
{
getLoaderManager().restartLoader(0, null, this);
}

//Instantiate and return a new Loader for the given ID.
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new GooTasksLoader(mActivity, this);
}

// Called when a previously created loader has finished its load.
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// Swap the new cursor in. (The framework will take care of closing
the
// old cursor once we return.)
mAdapter.swapCursor(data);
}

//Called when a previously created loader is being reset, thus making
its data unavailable.
@Override
public void onLoaderReset(Loader<Cursor> loader) {
// This is called when the last Cursor provided to onLoadFinished()
// above is about to be closed. We need to make sure we are no
// longer using it.
mAdapter.swapCursor(null);
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment