How to get _id on click in ListView?

In /layout/item.xml two TextView c a title and description (R. id.and R. id. tvText.tvTextDesc). Populate ListView from sqlite.


in the data array from sqlite
String[] from = { LINE_TITLE, LINE_DESC };<br>
int[] to = { R. id.tvText, R. id.tvTextDesc };<br>
SimpleAdapter sAdapter = new SimpleAdapter(this, data, R. layout.item, from, to);<br>
lvSimple = (ListView) findViewById(R. id.lvSimple);<br>
lvSimple.setAdapter(sAdapter);<br>
lvSimple.setOnItemClickListener(new OnItemClickListener() {<br>
 public void onItemClick(AdapterView<?> parent, View View, int position, long id) {<br>
}



Everything works. But it does not work in onItemClick to get the value of R. id.tvText (or _id) on click.

Moving cursor in the database for position? Tell me how to implement it? Or is there an easier way?
October 8th 19 at 02:56
3 answers
October 8th 19 at 02:58
Solution
You can save the _id using setTag to the View in getView method of the adapter.
Thank you. Still look for a decision on your method. I need the _id, so you do not write crutches - velva_Fah commented on October 8th 19 at 03:01
as I understood setTag can only be used with SimpleCursorAdapter? - velva_Fah commented on October 8th 19 at 03:04
October 8th 19 at 03:00
on the SelectedIndexChanged event you can do for example
Here's the article described how to do it, and examples
October 8th 19 at 03:02
If I understand correctly the question, then in onItemClick do view.findViewById(...).
Thank you, it worked. - velva_Fah commented on October 8th 19 at 03:05

Find more questions by tags Android