Android - 从ListView选择获取数据库ID [英] Android - Getting database ID from ListView selection
本文介绍了Android - 从ListView选择获取数据库ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 ListView lv
它使用来自SQL数据库的 Cursor c
来填充它。但是,当选择项目时,我需要获取行的ID。如何做到这一点?
I have a ListView lv
which uses a Cursor c
from an SQL database to populate it. When an item is selected however, I need to get the ID of the row. How can I do this?
推荐答案
我假设你使用的是SimpleCursorAdapter a href =http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html =nofollow> OnItemClickListener :
I assume that you are using a SimpleCursorAdapter (or similar), so I would use the OnItemClickListener:
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// id references the SQLiteDatabase _id column
}
});
这篇关于Android - 从ListView选择获取数据库ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文