你真的很震惊这个问题。我是android世界的新手。我有一个显示数据库信息的列表。(id,name和description)。在单击并保持操作时,我想从数据库中删除所选行。我已经实现了上下文菜单但是没有从数据库获取id但是返回位置(0但是db的id是1).thanx
我想我明白了:)
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
TextView ids = (TextView)findViewById(R.layout.list_row);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
int foldeiId=(Integer) adapter.getItem(position);
String fd = String.valueOf(view.getId());
// Log.w("Data id arunmr: ", foldeiId);
System.out.println(foldeiId);
menu.setHeaderTitle("Options");
menu.add(0, NEW_MENU_ITEM, foldeiId, "Delete");
menu.add(0, SAVE_MENU_ITEM, foldeiId, "Rename");
}
但任何想法如何从上下文菜单访问提到的“foldeiId”?
答案 0 :(得分:0)
试试这个 如果在oncreate()方法之外声明该变量
,则可以获得foldeiId@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Delete"){
// delete the item you want to delete
}
else if(item.getTitle()=="Rename"){
// rename the item you want to
}
else {return false;}
return true;
}