I have two spinners in my current android app, I would like to have a default value like the editText's android:hint ability. Is there a way to do so, but in a way that doesn't add the hint to the string array that populates the spinner. e.g. it's impossible to choose the hint from the spinner list.
Also, is there a way to check if the user has selected a valid value and if not take an action. I do this in my editTexts by getting the value to a string and then:
if (calculator_ShutterSpeed_TempValue.equals("") ){
action
}
And can I set the spinner back to it's hint value on another button press?
So what I am for asking is:
To set the default value in Spinner you have to set first that index selected setSelection(index)
and save it to the preferences by using SharedPreferences
. Please check out the code to set and load the preferences.
So onResume()
highlight that index value selected.
To get the value from spinner use spinner.getSelectedItem()
and cast it to String. Now you can compare it to your criteria.
To redisplay the hint, first it must be as an item in spinner and then regiter the OnItemSelectedListener. In that Listener's code reset the selected index to yout hint index again.