如何找到选择列表中的主键 [英] How to find the primary key of select list
本文介绍了如何找到选择列表中的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要展示我在列表视图数据的名称,并且不显示主键。现在,当我点击我会得到的名字,但我希望得到被点击的数据的主键。
I have to show the name of my data on a listview, and don't show the primary key. Now when I click I will get name, but I want to get the primary key of the data that was clicked.
public class list_view extends ListActivity{
DBAdapter db;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
//override method onCreate that Inheritance from Activity Class
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view);
db = new DBAdapter(this);
setListAdapter(new ArrayAdapter<String>(this,R.layout.row,R.id.label,db.query()));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method
String selection = l.getItemAtPosition(position).toString();
Toast.makeText(this, selection, Toast.LENGTH_SHORT).show(); //show in toast
}
}
db.query
只返回数据的名称。
推荐答案
您只需发送您选择的查询方法,然后查询最后使用moveToPosition()移动光标到您想要的信息列表中位置
you just sent position of list that you've selected to query method then query finally use moveToPosition() to move cursor to information that you want
这篇关于如何找到选择列表中的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文