Note that there are some explanatory texts on larger screens.

plurals
  1. PONew SimpleCursorAdapter whenever data changes?
    primarykey
    data
    text
    <p>I'm just starting out with Android development and have been building a simple app that uses a <code>ListActivity</code>, a <code>SQLiteDatabase</code>, and a <code>SimpleCursorAdapter</code>.</p> <p>On the Android developer website there is an example project that demonstrates the usage of the <code>SimpleCursorAdadpter</code>. Looking at the implementation, whenever the underlying database is modified as a result of some user action, the <code>ListActivity</code> explicitly calls the following function to "refresh" the list:</p> <pre class="lang-java prettyprint-override"><code>private void fillData() { // Get all of the rows from the database and create the item list mNotesCursor = mDbHelper.fetchAllNotes(); startManagingCursor(mNotesCursor); // Create an array to specify the fields we want to display in the list (only TITLE) String[] from = new String[]{NotesDbAdapter.KEY_TITLE}; // and an array of the fields we want to bind those fields to (in this case just text1) int[] to = new int[]{R.id.text1}; // Now create a simple cursor adapter and set it to display SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to); setListAdapter(notes); } </code></pre> <p>It looks like a new <code>SimpleCursorAdapter</code> is created every time and bound to the view with <code>setListAdapter()</code>. Is this the best/cleanest implementation? The fact that this is on the Android website lends it a lot of credibility, however I looked at the <code>CursorAdapter</code> documentation and saw there is a <code>changeCursor()</code> method that seems to lend itself to a cleaner implementation than the one above, but I'm just not sure what that might look like.</p> <p>Maybe I'm just fretting over nothing, but coming from the C/C++ world, and seeing this "new" object created each time you insert/delete a row from the database seems a bit heavy-handed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload