当我在应用程序中触摸按钮 2 或 3 秒时,我想要一个选项菜单。
示例:在消息应用程序中,当我触摸特定消息 2 到 3 秒时,会出现一个选项菜单,其中显示:
删除
副本、
锁定
转发
副本到 Sim
等。
那么我如何在我的应用程序中使用它呢?
我可以使用吗
onOptionsItemSelected
这个方法。或者其他的。
这里我还想要一件事,假设在上下文菜单中有五个操作,选择第五个操作后,第一个操作将禁用,只有当我选择第四个操作时才启用。
假设情况是:
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Option Menu");
menu.add(0, v.getId(), 0, "First Action");
menu.add(0, v.getId(), 0, "Second Action");
menu.add(0, v.getId(), 0, "Third Action");
menu.add(0, v.getId(), 0, "Fourth Action");
menu.add(0, v.getId(), 0, "Fifth Action");
}
现在当我选择第五个操作时,第一个操作将禁用,只有当我选择第四个操作时才启用。
请推荐我...
I want one option menu when I touch the button for 2 or 3 second in my application.
Example: In the Message Application when I touch particular message for 2 to 3 second then one option menu come which show:
Delete
copy
Lock
Forward
Copy to Sim
etc.
So how can I use this on my application.
Can I use
onOptionsItemSelected
this method.Or something else.
Here One more thing which I want, suppose in Context Menu Five Action is there and after selecting fifth action first action will disable and only enable when I select Fourth Action.
Suppose the cose is:
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Option Menu");
menu.add(0, v.getId(), 0, "First Action");
menu.add(0, v.getId(), 0, "Second Action");
menu.add(0, v.getId(), 0, "Third Action");
menu.add(0, v.getId(), 0, "Fourth Action");
menu.add(0, v.getId(), 0, "Fifth Action");
}
now when I select Fifth Action then First Action will disable and only enable when I select Fourth Action.
Please Suggest me...
发布评论
评论(3)
尝试使用 LongClickListener 作为按钮。它可能适合您的要求。
Try LongClickListener for the button. It may suite your requirement.
仅供参考,您所讨论的菜单称为上下文菜单,不是选项菜单。
此处给出了更详细的示例:http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/
菜单指南:http://developer.android.com/guide/topics/ui/menus.html
一旦你完成了例如,只需实现
OnLongClickListener
到你的按钮。FYI, the menu which you are talking about is known as Context Menu, not an Option Menu.
More detailed example is given here: http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/
Guidelines for Menu: http://developer.android.com/guide/topics/ui/menus.html
Once you are done with example, just implement
OnLongClickListener
to your button.尝试使用上下文菜单,这将特定于消息并且也很简单。它类似于选项菜单。
Try using context menu , this will be specific to the message and is easy as well. Its similar to options menu.