开发者

how to call context menu

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开发者_如何学C 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?


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.


You have the this which is also a view.


Perhaps what you are looking for is actually a submenu, where it allows you to popup a submenu upon clicking on the menu item.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜