如何调用上下文菜单 [英] how to call context menu

查看:158
本文介绍了如何调用上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

注册上下文菜单时要允许用户通过点击长时间打开它。如果你想以编程方式打开它,你只需要调用<一个href="http://developer.android.com/reference/android/app/Activity.html#openContextMenu%28android.view.View%29">openContextMenu.作为获得视图,您可以使用<一个href="http://developer.android.com/reference/android/app/Activity.html#findViewById%28int%29">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.

这篇关于如何调用上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆