In my application, I have a ListView in my main layout. In the corresponding Activity, I have the following in my onCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
app = (MyTallyKeeperApplication) getApplication();
adapter = new TallyItemListAdapter(this, app.getTallyItems());
setListAdapter(adapter);
registerForContextMenu(getListView());
}
Each item in the ListView is of type TallyItemView, inheriting from LinearLayout. The code I used to inflate the context menu is:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
Log.i(MyTallyKeeperMain.class.getSimpleName(), "onCreateContextMenu");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.item_menu, menu);
}
In theory, when you long press on an item, you are shown a context menu which gives you options to edit that item or delete it. But when I long press on an item, nothing is shown.
Any ideas as to how I can fix this?
This happens if the list has focusable items (checkbox etc.) In the layout of the list row include this for the focusable components.