0

I would like to get the values from database of a particular column by executing a query. Is it possible to do it after we do it to the Cursor Adapter or can we attain the values well before itself. Kindly help on this with a snippet or a guide.

tobiasbayer
  • 10,269
  • 4
  • 46
  • 64
Karthik
  • 4,943
  • 19
  • 53
  • 86
  • See it here: http://stackoverflow.com/questions/3544913/android-how-to-use-cursoradapter – aF. Dec 19 '11 at 10:13

1 Answers1

2
Context context = getApplicationContext(); 
final DataBaseHelper db = new DataBaseHelper(context);
...
...
db.createDataBase();
..
...try catch logic etc
....
final Cursor c = db.getAllRows();
....
c.getString(4) // String value of 5th Column in Database

Cursor Adapter to Array

ArrayList<String> mArrayList = new ArrayList<String>(); 
c.moveToFirst(); 
while(!c.isAfterLast()) { 
     mArrayList.add(c.getString(c.getColumnIndex(DataBaseHelper.KEY_NAME)); 
     c.moveToNext(); 
} 

DataBaseHelper class has following

public Cursor getAllRows() 
    {
        return myDataBase.query(DATABASE_TABLE, new String[] {
                KEY_ROWID, 
                KEY_NAME,
                KEY_YEAR,
                     KEY_QUOTE,
                     KEY_REF}, 
                null, 
                null, 
                null, 
                null, 
                null);
    }
duggu
  • 37,851
  • 12
  • 116
  • 113