如何创建一个Android微调作为一个弹出?弹出、作为一个、创建一个、Android

2023-09-12 11:31:38 作者:孤枕

我要当用户点击菜单项,让用户选择一个项目,弹出一个对话框微调。

我需要为这个单独的对话框或者我可以直接用微调?我看到此链接,提到了MODE_DIALOG选项,但似乎并没有再被定义。 AlertDialog可能是确定的,但所有的选项说点击的项目列表中不会关闭对话框,这是我想要的。任何建议?

理想情况下,code将类似的地方微调显示在屏幕上的情况:

  ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>(活动,
     android.R.layout.simple_spinner_item,项目);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
myspinner.setAdapter(适配器);
// myspinner.showAsDialog()<  - 我想要什么
 

解决方案

您可以使用一个警告对话框

  AlertDialog.Builder B =新生成器(本);
    b.setTitle(示例);
    的String []类型= {通过邮编,按类别};
    b.setItems(类型,新OnClickListener(){

        @覆盖
        公共无效的onClick(DialogInterface对话,诠释它){

            dialog.dismiss();
            切换(这){
            情况下0:
                onZi prequested();
                打破;
            情况1:
                onCategoryRequested();
                打破;
            }
        }

    });

    b.show();
 
迅雷怎样不弹出 建立新任务 小窗口

这将关闭对话框时,其中一人是pssed像你是想$ P $。希望这有助于!

I want to bring up a spinner dialog when the user taps a menu item to allow the user to select an item.

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             

解决方案

You can use an alert dialog

    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!