您好想知道我们能否从 onContextItemSelected() 中的数据库中获取列表中定义的字段的值,例如 id?我创建上下文菜单的代码固定在下面,感谢帮助,谢谢
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
long clickedPosition = info.id;
switch (item.getItemId()) {
case NEW_MENU_ITEM:
//callActivity(1);
break;
case SAVE_MENU_ITEM:
//callActivity(2);
break;
}
return super.onContextItemSelected(item);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
menu.setHeaderTitle("Options");
menu.add(0, NEW_MENU_ITEM, 0, "Delete");
menu.add(0, SAVE_MENU_ITEM, 1, "Rename");
}
以下代码不会从数据库中停用我的 ID
long clickedPosition = info.id;