Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 308
domen Avatar asked Feb 11 '13 16:02

domen


2 Answers

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.

like image 75
Jijo Thomas Avatar answered Sep 28 '22 05:09

Jijo Thomas


SimpleCursorAdapter isn't deprecated, just the constructor.

see SimpleCursorAdapter deprecated in API version 15?

like image 42
Gal Ben-Haim Avatar answered Sep 28 '22 06:09

Gal Ben-Haim