In two parts of my app I have spinners. One spinner provides a set of strings, and the one I'm currently working on is supposed to allow the user to select a preset number (10, 25, 50, 100) of questions to take a practice test with that many questions.
I figured it'd be a simple copy/paste of the current spinner that works, while just changing the toString();
to toInteger();
but it doesn't seem to be the case. As I looked up how to retrieve an integer from a spinner, it looks significantly different than how I implemented my spinner of Strings. I know there's more than one way to do most things, but I'm curious if there's a direct translation from strings to integers when using spinners?
Basically, how do I use the same setup to achieve a spinner for integers?
Java Method:
//Get spinner selection
final Spinner userInputSpinner = (Spinner) findViewById(R.id.feedbackSpinner);
String TYPE = userInputSpinner.getSelectedItem().toString();
XML Spinner:
<Spinner
android:id="@+id/feedbackSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:prompt="@string/feedbackType"
android:entries="@array/feedbackChoice"/>
Arrays XML:
<!--ARRAY FOR FEEDBACK SPINNER-->
<string-array name="feedbackChoice">
<item>@string/feedbackCompliment</item>
<item>@string/feedbackSuggestion</item>
<item>@string/feedbackWrong</item>
<item>@string/feedbackIssue</item>
</string-array>
Aucun commentaire:
Enregistrer un commentaire