SimpleCursorAdapter alternative

domen picture domen · Feb 11, 2013 · Viewed 14.5k times · Source

I'm using the deprecated SimpleCursorAdapter to display data from Cursor to ListView. I've added the additional argument 0, which removes the dreprecated warning, but I want to use a better way to display data. I've read something about Loader, but don't know how to implement it. What would be a better alternative to the code below? How would this code be translated to use Loader?

Cursor c = mDbHelper.getAllRecords();
    startManagingCursor(c); //this is also deprecated

    String[] from = new String[] { "Name" };
    int[] to = new int[] { R.id.text1 };

    SimpleCursorAdapter names =
        new SimpleCursorAdapter(this, R.layout.names_row, c, from, to, 0);
    setListAdapter(names);

Answer

Jijo Thomas picture Jijo Thomas · Jul 9, 2013

adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from, to, 1);

This will do the automatic requery. 1 is set to true and 0 to false.