How do I create an Android Spinner as a popup?(如何将 Android Spinner 创建为弹出窗口?)
问题描述
我想在用户点击菜单项以允许用户选择一项时调出一个微调对话框.
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 创建为弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 Android Spinner 创建为弹出窗口?


- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01