S
S
stilg2012-02-24 10:04:14
Android
stilg, 2012-02-24 10:04:14

How to get _id on click in ListView?

/layout/item.xml has two TextViews with title and description (R.id.tvText and R.id.tvTextDesc). I fill ListView from sqlite.
to 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&lt;?&gt; parent, View view, int position, long id) {<br/>
}

Everything is working. But it is not possible to get the value of R.id.tvText (or _id) on click in onItemClick.
Move cursor in base by position? Tell me how to implement it? Or is there an easier way?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
falstaf, 2012-02-24
@stilg

You can store the _id via setTag on the View, in the adapter's getView method.

M
Maxim Tkachuk, 2012-02-24
@makzimko

on the SelectedIndexChanged event, you can do it, for example.
The article describes how to do it, and with examples

F
falstaf, 2012-02-24
@falstaf

If I understand the question correctly, then in onItemClick do view.findViewById(...).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question