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.

1

1 Answer 1

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);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.