且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-30 14:47:34

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

  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!