Search code examples
androidandroid-fragmentactivityandroid-adapterandroid-cursorandroid-cursorloader

How to load and bind the data to ListFragments inside FragmentActivity


I've got a FragmentActivity which hosts six ListFragments (and each hosts a ListView with thousand of entrys). I can do a search over all Fragments in one action in the title bar and then wipe through the resulting lists.

Now my question: How do I load and bind the data to the six ListViews? - In detail: Should I manage six CursorAdapters in the FragmentActivity? Or just one single CursorAdapter for all the six ListViews (as seen below)? Should I make use of a CursorLoader (as it manages just one single Cursor object)?

/**
* Moves the query results into the adapter, causing the
* ListView fronting this adapter to re-display
*/
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
   mAdapter.changeCursor(cursor);
}

Solution

  • I would say one cursor/loader for each list. It's always good to refactorize so it is up to you to create the class you need but you should use diferent adapter for each list i think

    Cursor loader :

    http://developer.android.com/reference/android/content/CursorLoader.html

    Little tuto :

    http://mobile.tutsplus.com/tutorials/android/android-sdk_loading-data_cursorloader/