I have a ListView that creates ContextMenu when a long click of one of its elements. How to find the item that was selected in the ListView that created this context menu (and not the selected MenuItem)? Here is my code:
list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, final View v, ContextMenuInfo menuInfo) { menu.setHeaderTitle("Actions"); android.view.MenuItem remove = menu.add("Remove"); final int selectedItem = ((ListView)v).getSelectedItemPosition(); remove.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(android.view.MenuItem item) { doSomething(listAdapter.getItem(selectedItem));
Please note that I do not want the item to be selected from the context menu, but the ListView element that called this context menu.
source share