之后,按一下按钮Android的开放上下文菜单
问题描述:
我想打开快捷菜单,当我点击一个按钮,但我也必须知道哪些列表项的重点是,当我按一下按钮。你知道该怎么做?什么code应该在的onclick
的方法?
I want to open context menu when I click a button, but also I have to know which list item is focused when I click the button. Do you know how to do that? What code should be in onclick
method?
答
我一直在寻找相同的,并且发现,而不是上下文菜单,你应该使用对话框
I was looking for the same, and found that instead of context menu, you should use Dialogs
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();
http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog