views:

118

answers:

1

hi Friends,

i have been using a SQLite database, Theres a situation where i have a list which displays all the "name" field data of a table "table1". Now i have a button to insert data in "table1". The list is populated using a simple cursor adapter which is passed a cursor "cursor1" populated with the data. "cursor1" is prepared using the SQLite query - "SELECT * FROM table1". Now the moment i insert data, i need to update the list too.

My question is-

  1. will the Adapter sense the database change automatically (i guess not)?
  2. using cursor1.requery() is correct or should i use cursor1 = db.query("table1", null, null, null, null, null, null);

It would be helpful if you can throw some light on which 1 is better and in which situation. Coz for the situation which i explained above, the requery() command is not giving a valid result while the later 1 works fine. still cant understand what the problem could be.

A: 

will the Adapter sense the database change automatically (i guess not)?

No, the Adapter will not sense the database change automatically.

using cursor1.requery() is correct or should i use cursor1 = db.query("table1", null, null, null, null, null, null);

Use requery(). Here is a sample project from one of my books demonstrating the technique.

CommonsWare
well thanx a lot Mark! but i use a code where i insert some values in "table1" and then call the requery function, This didnt workout. The table was initially empty, later i inserted the value and the requery didnt return any result. But when i used cursor1 = db.query("table1", null, null, null, null, null, null); , it returned me the values... wat should i understand from this??Please throw some light on this...
JaVadid