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

后端 未结 5 742
北海茫月
北海茫月 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: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();
    

提交回复
热议问题