我想在用户点击菜单项以允许用户选择一项时调出一个微调对话框.
I want to bring up a spinner dialog when the user taps a menu item to allow the user to select an item.
我需要一个单独的对话框,还是可以直接使用 Spinner?我看到 这个链接, 提到了一个 MODE_DIALOG 选项,但它似乎不再被定义了.AlertDialog 可能没问题,但所有选项都说单击列表中的项目不会关闭对话框",这是我想要的.有什么建议吗?
Do I need a separate dialog for this or can I use Spinner directly? I see this link, mentions a MODE_DIALOG option but it doesn't seem to be defined anymore. AlertDialog may be OK but all the options say "clicking on an item in the list will not dismiss the dialog" which is what I want. Any suggestion?
理想情况下,代码类似于屏幕上显示微调器的情况:
Ideally, the code would be similar to the case where the spinner is shown on the screen:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
myspinner.setAdapter(adapter);
// myspinner.showAsDialog() <-- what i want
你可以使用警告对话框
AlertDialog.Builder b = new Builder(this);
b.setTitle("Example");
String[] types = {"By Zip", "By Category"};
b.setItems(types, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
switch(which){
case 0:
onZipRequested();
break;
case 1:
onCategoryRequested();
break;
}
}
});
b.show();
当您想要按下其中一个时,这将关闭对话框.希望这会有所帮助!
This will close the dialog when one of them is pressed like you are wanting. Hope this helps!
这篇关于如何将 Android Spinner 创建为弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!