如何调用上下文菜单上下文、菜单

2023-09-06 10:01:23 作者:流年的顛簸。

我打开我的上下文菜单是这样的:

I open my context menu like this:

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

我怎么能叫

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?

推荐答案

注册上下文菜单时要允许用户通过点击长时间打开它。如果你想以编程方式打开它,你只需要调用openContextMenu.作为获得视图,您可以使用findViewById如果你给它一个id或保存在您的活动类的属性。

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.

上一篇:从形象定位形象

下一篇:净矩阵矩阵