dev_android
dev_android

Reputation: 8818

Android get value of any column from any cursor giving the corresponding id

I have created Cursor from any database table. It consists value of _id and corresponding name. For further operation, I need the value of "name" for any specific "_id". How it is possible using the Cursor.

Upvotes: 1

Views: 6557

Answers (2)

RaviPatidar
RaviPatidar

Reputation: 1486

Very Simple you can get it by either of following way

String id = cursor.getString( cursor.getColumnIndex("id") ); // id is column name in db

or

String id = cursor.getString( cursor.getColumnIndex(0)); // id is first column in db

Upvotes: 0

Ashwani Tyagi
Ashwani Tyagi

Reputation: 508

String selecttSqlStr2 = "SELECT * FROM Tablename  WHERE TRIM(QST_Id) = '" + _id;

Cursor c = datasource.execSelectSQL(selecttSqlStr);//datasource is object for opening database
c.moveToFirst();
String name=c.getString(c.getColumnIndex("name"));

Upvotes: 3

Related Questions