[android-beginners] Re: Problem with Cursor Adapter not updating

2009-10-29 Thread skataben

Bump. I have the same question. Right now, I'm using the code below.
There's got to be a simpler way.

private void updateListview() {
// Close the old Cursor
if(mCursorAdapter != null) {
Cursor c = mCursorAdapter.getCursor();
c.close();
}

// Create the new Cursor.
Cursor c = this.queryAllUsernames();
mCursorAdapter = new SimpleCursorAdapter(this,
R.layout.singleitem_row, c, FROM_COLUMNS, TO_VIEWS);
setListAdapter( mCursorAdapter );
}

On Oct 15, 10:09 pm, jax jackma...@gmail.com wrote:
 I have a CursorAdapter attached to a ListView

 I then delete a row from the database by using acontextmenuand call
 notifyDataSetChanged() on the adapter.

 The problem is that the ListView does not update until I quit the
 activity and re-enter.

 What am I doing wrong?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Problem with Cursor Adapter not updating

2009-10-29 Thread Mark Murphy

skataben wrote:
 Bump. I have the same question. Right now, I'm using the code below.
 There's got to be a simpler way.
 
   private void updateListview() {
   // Close the old Cursor
   if(mCursorAdapter != null) {
   Cursor c = mCursorAdapter.getCursor();
   c.close();
   }
 
   // Create the new Cursor.
   Cursor c = this.queryAllUsernames();
   mCursorAdapter = new SimpleCursorAdapter(this,
 R.layout.singleitem_row, c, FROM_COLUMNS, TO_VIEWS);
   setListAdapter( mCursorAdapter );
   }

Just call requery() on the Cursor, and the rest will take care of
itself. You do not need to do anything else.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 1.0 In Print!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---