tags:

views:

180

answers:

2

I open my context menu like this:

 private OnClickListener optionsClickListener = new OnClickListener()
 {
  public void onClick( View v )
  {
    registerForContextMenu( v );
    openContextMenu( v );
  }
 };

How can I call

registerForContextMenu( v );
openContextMenu( v );

from inside my regular menu handler here:

 public boolean onOptionsItemSelected( MenuItem item )
 {
  switch( item.getItemId() )
  {
    case OPTIONS:
      registerForContextMenu( v );
      openContextMenu( v );
      return true;

where I have no View to pass?

A: 

You have the this which is also a view.

CaseyB
In the context I described, "this" is an Activity, not a View.
gdonald
What are you doing to the view in these methods? The view that you're passing in isn't your main view, it's the view that got the event, so the button or whatever.
CaseyB
onOptionsItemSelected() does not provide access to a View. It provides access to a MenuItem. How do I call registerForContextMenu() and openContextMenu() in the context of onOptionsItemSelected() where I only am given a MenuItem, not a View? How do I get the current View from the MenuItem? item.what?.what? ?
gdonald
Ok, I am completely confused as to what you are trying to accomplish. From a users standpoint you want them to press the menu button and select the "Options" menu item and that should pop up another menu? The point of a ContextSensitiveMenu is that it offers options that are specific to whatever it is you clicked on. They aren't meant to control options for an app. If that's what you want you should use a custom dialog or a new activity.
CaseyB
Sorry you're confused, it's really not that hard to understand, I just want to know how to open a context menu from a menu item click. I'm going to assume it can't be done at this point since no one knows how. Thanks all the same.
gdonald
A: 

Registering a context menu is when you want to allow the user to open it by long clicking. If you want to open it programmatically, you simply have to call openContextMenu. As for obtaining the view, you can either use findViewById if you gave it an id or save it as an attribute in your Activity class.

Casebash