将单选按钮添加到上下文菜单
我想将单选按钮添加到我的上下文菜单中,但我不知道如何添加。它是这样创建的:
@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");
}
I would like to add radio buttons to my context menu, but I'm not sure how. This is how it is created:
@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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的代码中:
v 是一个视图,可以是 RadioButton 或任何其他类型的视图。
如果您不使用 xml 来定义 RadioButton。你应该在你的应用程序中设置它的ID。
v.setId();
或者您可以在 res/values 中定义 ids.xml。
示例/ApiDemos/src/com/example/android/apis/RadioGroup1.java 示例/ApiDemp/res/values/ids.xml
菜单和示例上下文菜单开发人员指南:
http://developer.android.com/guide/topics /ui/menus.html
如果您滚动上面的页面,您可以在上下文菜单中找到 RadioButton 示例。
引用以上页面:
如果不设置checked状态
from your code:
v is a View that can be a RadioButton or any other type of Views.
if you are not using xml to define RadioButton. you should set its ID in your application.
v.setId();
Or you can define ids.xml in res/values.
samples/ApiDemos/src/com/example/android/apis/RadioGroup1.java samples/ApiDemp/res/values/ids.xml
Menu & Context Menu developers guide:
http://developer.android.com/guide/topics/ui/menus.html
if you scroll the above page you can find RadioButton sample in context menu.
Quote form the above page:
If you don't set the checked state
我没有尝试过,但我希望它能起作用:
I didn't try it but I hope it works: