OnCreateContextMenu not called

It looks like onCreateContextMenu is not called at all. In my onCreate for my ListActivity, I have:

list = getListView(); registerForContextMenu(list); 

(I know this is redundant, and I just passed getListView () with the same results).

Here is my onCreateOntextMenu;

 @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); Log.d("LM", "onCreateContextMenu"); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.context_landmarks, menu); } 

The log is never generated. Anyone have no suggestions?

+6
source share
6 answers

My thought is to catch the ListView event, not go into contextMenu behavior. This makes sense to me because the behavior of OnItemLongClickListener overlaps contextMenu. If not, how can it recognize between contextMenu and OnItemLongClickListener?

+8
source

Try to find registerForContextMenu (list); as the last call invocation method in the onCreate method. I mean that this shoul method is called after the list adapter is called not earlier.

0
source

Just remove youwidget.setonLongclicklistener and yourwidget.setLongClickable

And then add registerforContextmenu(yourwidget) to onCreate() then add the code according to the widgets used.

Hope this will be helpful.

0
source

My problem was very closely related to lulumeya's answer, which pointed me in the right direction. I have done context menus many times before and somehow I have never encountered this until now.

I called View.setOnClickListener(listener) in Adapter.getView(...) when it should be ListView.setOnItemClickListener(listener) to avoid a conflict with the context menu.

In general, I am sure that OnItemClickListener is more optimized, especially since instead of creating a new instance each time a view is created or processed, only one instance of the listener is used.

0
source

I had this problem, and I could only solve it with

  • because Activity registered views, the same action should also override onCreateContextMenu (); will not do this in the Fragment.
  • since I used an additional fragment creating the Adapter (and registering with it), the Fragment not Activity should override onContextItemSelected ().

I am considering abandoning a long pop-up window in favor of a Youtube-style button on the right edge of the cards that pops up from a menu that doesn't fade everything else from the background --- what kind of search query for this btw?

0
source

You must call the registerForContextMenu(View view) method on onCreate(Bundle savedInstanceState) .

-2
source

Source: https://habr.com/ru/post/907177/


All Articles