问题描述
我想在用户点击菜单项以允许用户选择一项时调出一个微调对话框.
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 创建为弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)