我有一个包含两列category_id和name的类别表.我创建了一个名为CategoryDataHelper的数据助手类.我有一个名为getCategoryCursor()的方法,该方法从类别表中获取id和名称并返回游标.使用该游标,我使用SimpleCursorAdapter显示类别列表.它工作正常.
public class Categories extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
categoryDataHelper = new CategoryDataHelper(getApplicationContext());
Cursor categoryCursor = categoryDataHelper.getCategoryCursor();
ListAdapter adapter = new SimpleCursorAdapter (
this,
android.R.layout.simple_list_item_1,
categoryCursor,
new String[] { CategoryDataHelper.NAME },
new int[] {android.R.id.text1});
// Bind to our new adapter.
setListAdapter(adapter);
list = getListView();
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
// Here I want the category_id
}
});
}
}
现在我想实现OnItemClickListener并使用所选类别的category_id发送Intent.如何在onItemClick()方法中获取id?