java - How can we use an ID from database as Listview ID using SimpleCursorAdapter? -


i new android , started work on databases , listview. want use subjectid id of listview created. can use id query records database when item tapped. know asked many times nothing seems work on me. in advance help.

part of sql: subjectid _id

i have piece of codes:

 string[] datacolumns = { "subjectname","shortemail", "lastscandate", "lastscore" } ; int[] viewids = { r.id.list_column1 , r.id.list_column2, r.id.list_column3, r.id.list_column4  };    simplecursoradapter adapter         = new simplecursoradapter(                   this,                             // context listview                   r.layout.subject_line,          // points xml list item                   cursor,                           // cursor items                   datacolumns,                   viewids           );       setlistadapter(adapter);     db.close();    public void onlistitemclick(listview l, view v, int position, long id) {  //codes here  } 

if read sourcecode of cursoradapter, can find:

   public long getitemid(int position) {         if (mdatavalid && mcursor != null) {             if (mcursor.movetoposition(position)) {                 return mcursor.getlong(mrowidcolumn);             } else {                 return 0;            }         } else {            return 0;        }     } 

and mrowidcolumn assigned:

 mrowidcolumn = cursorpresent ? c.getcolumnindexorthrow("_id") : -1; 

these mean, if use "_id" database id, getitemid() database's id.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -