Deepak
Deepak

Reputation: 1258

Update sqlite cursor when table records changes?

I have a Broadcast Receiver that inserts info into a table when sms is received. In the main activity i have a Cursor from a query on that table. Is it possible for me to set the cursor to requery every time the BR makes changes to the Table, so that it can reflect in the cursor.

I am currently not using OpenHelper, simply opening the database in the Activity and doing a query to obtain a cursor.

Upvotes: 2

Views: 1163

Answers (1)

Sam
Sam

Reputation: 86948

Yes, this is possible and probably easy.

  • If you are using a Cursor, you should be using a CursorAdapter. Simply request a new Cursor and pass it to your adapter with swapCursor().
  • If you are using some other form of adapter, like an ArrayAdapter, call add() or insert().

Either of these methods cause the View bound to your adapter to refresh automatically.

Upvotes: 1

Related Questions