How to popup list like a spinner without spinner in android?

后端 未结 5 736
北海茫月
北海茫月 2021-02-06 11:51

I have a spinner widget in my activity which lets users pick a list name.

Normally, the function of the spinner is to switch between lists but for a couple of instances,

相关标签:
5条回答
  • 2021-02-06 12:18

    You might want to use PopupMenu

    see this example

    0 讨论(0)
  • 2021-02-06 12:20

    If you are not limited by API level 11 then listPopupWindow is close to what you want.

    0 讨论(0)
  • 2021-02-06 12:28

    Use AlertDialog.Builder and supply an Adapter via setAdapter() that generates your rows.

    In your case, I would not use the same Cursor, as a Cursor has an intrinsic notion of the current row, and so messing with the Cursor while it is used by your SpinnerAdapter could screw up the Spinner. Go with an identical Cursor.

    0 讨论(0)
  • 2021-02-06 12:37

    This is best example for popup details like spinner using AlertDialog and AlertDialog.Builder

            AlertDialog dialog;
    
             final CharSequence[] items = { "Item1", "Item2" };
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(title);
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int pos) {
                switch (pos) {
                    case 0:
                                  {
            Toast.makeText(this,"Clicked on:"+items[pos],Toast.LENGTH_SHORT).show();
    
                          }break;
                case 1:
                                  {
            Toast.makeText(this,"Clicked on:"+items[pos],Toast.LENGTH_SHORT).show();
    
                          }break;
            }
        }});
    dialog=builder.create();
    dialog.show();
    
    0 讨论(0)
  • 2021-02-06 12:39
                CharSequence[] items = {"Mangoes", "Bananas", "Grapes"};
    
                new AlertDialog.Builder(getActivity())
                .setTitle("Action")
                .setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int item) {
    
                        if(item==0){
                          // Mangoes selected
                        }
                        else if(item==1){
                          // Bananas selected
                        }
                        else if(item==2){
                          // Grapes selected
                        }   
                    }
    
                })
                .show();
    
    0 讨论(0)
提交回复
热议问题