I'm trying to get a Spinner to load up with no selected value. Once the user selects a value it then takes them to another page.
This is proving to be a problem because at present, the page just loads straight away before the user gets a choice to choose.
My spinner class is set up the same way as Google's: http://developer.android.com/resources/tutorials/views/hello-spinner.html
So basically, is it possible have a spinner that loads with nothing selected because at present, it loads the first item in my string array.
This example demonstrates how do I make an android spinner with initial default text in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
when you select one of your first spinner Items you can use code below in first spinner onItemSelected() method to clear your second spinner. Show activity on this post. You have called spinner2List. clear(); but haven't notified the adapter by using notifyDataSetChanged(); method.
Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it.
is it possible have a spinner that loads with nothing selected
Only if there is no data. If you have 1+ items in the SpinnerAdapter
, the Spinner
will always have a selection.
Spinners
are not designed to be command widgets. Users will not expect a selection in a Spinner
to start an activity. Please consider using something else, like a ListView
or GridView
, instead of a Spinner
.
EDIT
BTW, I forgot to mention -- you can always put an extra entry in your adapter that represents "no selection", and make it the initial selected item in the Spinner
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With