domen
domen

Reputation: 1279

SimpleCursorAdapter alternative

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);

Upvotes: 12

Views: 14816

Answers (2)

Jijo Thomas
Jijo Thomas

Reputation: 875

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.

Upvotes: 7

Gal Ben-Haim
Gal Ben-Haim

Reputation: 17813

SimpleCursorAdapter isn't deprecated, just the constructor.

see SimpleCursorAdapter deprecated in API version 15?

Upvotes: 6

Related Questions