如何与onListItemClick从数据库中获得价值? [英] How to get value from database with onListItemClick?
问题描述
我可以添加到一个数据库和列表作为列表视图。当我使用单击列表项 onListItemClick
,我需要获得的价值是什么说法?这很紧急;请code解释。先谢谢了。
I can add to a db and list as a listview. When I click a list item using onListItemClick
, what statement do I need to get the value? It's urgent; please explain with code. Thanks in advance.
String[] from = new String[] {NotesDbAdapter.KEY_BODY, NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_NUMBER};
int[] to = new int[] {R.id.toptext, R.id.middletext, R.id.circle};
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.row, notesCursor, from, to);
setListAdapter(notes);
//some other code
protected void onListItemClick(ListView l, View v, int position, long thisID)
{
super.onListItemClick(l, v, position, thisID);
**String **resposponseid** = Activity2.getData();**
}
我已经responseid独特的,我想,当我点击列表中的位置使用的每一行。所以,当我点击列表如何让responseid?
I have responseid for every row unique which I want to use when I click on list position. So how to get responseid when I click on list?
推荐答案
在 onListItemClick
方法,参数 INT位置
正是你要寻找的。该名单是由填补了一个 ArrayAdapter
,它利用一些列表
(比方说一个的ArrayList
)来获取每一行的意见。
In the onListItemClick
method, the parameter int position
is exactly what you're looking for. The list is filled by an ArrayAdapter
which utilizes some List
(let's say an ArrayList
) to get Views for each row.
这是每行中的视图可以pretty复杂的(不是由单个值)的事实,导致了它的实现方式,而你没有得到本身的价值,但在位置名单。你需要做的就是价值是什么来查询的ArrayList
(其 GET(INT指数
)方法)你用于填充的ListView
与位置参数。
The fact that the View in each row can be pretty complicated (not consist of a single value), leads to the way it is implemented, and you don't get the value itself, but the position in the list. What you need to do to get the value is to query that ArrayList
(its get(int index
) method) you used to fill the ListView
with the position param.
这篇关于如何与onListItemClick从数据库中获得价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!