dimanche 8 février 2015

Android : How to create Cursor object to get item id in SQLite?


public int getItemIdByPosition(int position) {

SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + TABLE_NAME, null);
cursor.moveToPosition(position);
return Integer.parseInt(cursor.getString(0));
}


I call this method from listview activity to get id of the item selected from listView. I have created Cursor object in my method but it doesn't fetch item id from database. What is the right way to get item id from database?


Aucun commentaire:

Enregistrer un commentaire