How do I create an Android Spinner as a popup?

后端 未结 12 1778
梦如初夏
梦如初夏 2020-12-02 09:20

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 dir

12条回答
  •  误落风尘
    2020-12-02 09:38

    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!

提交回复
热议问题