How to Create an Android Spinner as a Popup

How do I create an Android Spinner as a popup?

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.

Android: spinner popup is not working but its working as dropdown, how to change this dropdown into popup

Try this solve your problem 

<Spinner
android:id="@+id/switch_role_spinner"
android:layout_width="275dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:spinnerMode="dropdown"
style="@android:style/Widget.Spinner.DropDown"
android:layout_marginTop="20dp" />

Android spinner items in popup

From Holo Theme spinner shows as drop-down by default. If you want to customise this
you can use button and set spinner background, when the button taped, show the context menu.

UPDATE :

simply use android:spinnerMode="dialog"



Related Topics



Leave a reply



Submit