Android NULL menuInfo in onCreateContextMenu and onContextItemSelected only with manual call to openContextMenu in onListItemClick. Long click works

让人想犯罪 __ 提交于 2019-12-04 13:06:27

I had a very similar issue today, and the fix was unexpectedly simple but I don't understand why, but I'll post it here anyway.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    m_contextMenu = true;
    registerForContextMenu(parent);
    m_listView.showContextMenuForChild(view);
    unregisterForContextMenu(parent);
    m_contextMenu = false;
}

I use the m_contextMenu boolean to indicate that the context menu is being shown, I have an onItemLongClickListener that returns false if m_contextMenu is true so that the context menu does show up (if onItemLongClick() returns true, it won't show the context menu).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!