[英]how to create context menu for listview
我创建了一个对话框,在该对话框中有一个列表视图。 我已经为该listView创建了一个上下文菜单。 它显示了上下文菜单,但是当我单击该上下文菜单项时,它不起作用。
谁能帮我这个忙。
请通过使用以下代码检查您可以在Listview中创建上下文菜单::
创建功能
@Override public boolean onContextItemSelected(MenuItem item) { int menuItemId = item.getItemId(); //to find out the id AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int currentSelectionItemPosition = menuInfo.position; //moving the cursor to the selected position in the list view restaurantFavoritesCursor.moveToPosition(currentSelectionItemPosition); int restaurantid = restaurantFavoritesCursor.getInt(idColumnIndex); if(menuItemId == R.id.deleteFavoriteRestaurant) { //write the Action } return true; }
在Oncreate或OnStart内部注册事件
registerForContextMenu(listviewobject);
尝试上面的代码,我希望它能工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.