我怎么可以创建多个上下文菜单? [英] How can I create multiple context menus?
问题描述
我有1活动,但想有多个上下文菜单对不同的UI组件。
I have 1 activity, but would like to have multiple context menu's for different UI components.
例如,我有一个ListView这将作出反应:
For example, I have a ListView which will react to:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Selection Options");
menu.add(0, v.getId(), 0, "Remove");
}
我怎样才能创建另一个上下文菜单onclick事件的ImageView的我?
How can I create another context menu for the onClick event for an ImageView I have?
推荐答案
其实,这个方法是动态地更改选项菜单。创建几个上下文菜单,你有你的方法 onCreateContextMenu
来定义它们。正如你所看到的,这个方法接收查看参数,它是您点击使菜单显示视图。所以,你让你有你的的ListView
的方法,并且添加一些条件来区分你的查看
。然后使用这些条件来创建想要右键菜单
。
Actually, this method is to change the option menu dynamically. To create several context menus, you have to define them in your method onCreateContextMenu
. As you can see, this method receives a View as parameter, which is the View you clicked on to make the menu appear. So you keep the method you have for your ListView
, and you add some conditions to differentiate your Views
. Then you use these conditions to create the wanted Context Menu
.
注意:上下文菜单不支持图标的,所以如果你想图标,图像或类似的东西,你必须要么使用一个选项菜单中,你动态修改,或创建一个自定义菜单自定义视图,意图和一切。
Note : Context Menus don't support icons, so if you want icons, images or something similar you will have to either use an option menu you dynamically change, or create a custom menu with a custom view, intents and everything.
这篇关于我怎么可以创建多个上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!