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
Mobile Chrome Fires Resize Event on Scroll
Set a Consistent Style to All Edittext (For E.G.)
Should I Use Getapplicationcontext or Activity.This in a Long Running Asynctask
Android: Is There Any Free PDF Library for Android
Android Studio 3.1 Edittext Stackoverflowerror
How to Hide The System/Navigation Bar in Android Ics
Multiple Notifications to The Same Activity
Android Detect Webview Url Change
What Is Better: @Suppresslint or @Targetapi
How to Get The Time Spent on an Application in Android Programmatically
How to Replace The Activity's Fragment from The Fragment Itself
How to Place App Icon on Launcher Home Screen
How to Resolve Target 'Android-16'
Failed to Find Build Tools Revision 21.1.1 - Sdk Up to Date