1
Hello, good evening. In my project I have a spinner
<Spinner
android:id="@+id/spnCategorie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/categories_array"
android:prompt="@string/categories_prompt" />
That one spinner is responsible for adding the value in the column CATEGORIE in my database through the class Insertproduct.class.
The categories that populate this spinner is the following:
<string-array name="categories_array">
<item>Mantimentos</item>
<item>Açougue</item>
<item>Peixaria</item>
<item>Frios</item>
<item>Hortifruti</item>
<item>Café da Manhã</item>
<item>Higiene</item>
<item>Limpeza</item>
</string-array>
I’m converting the value of spinner for String to insert into the banco de dados as follows. (I don’t know if it’s the right way.)
Spinner CATEGORIE = (Spinner) findViewById(R.id.spnCategorie);
String stringCATEGORIE = CATEGORIE.getSelectedItem().toString();
...
I have another class (Alterproduct.class) responsible for changing the values of products, would like the spinner class Alterproduct.class return the category saved in the database.
Ex: My product has been entered in the database with the category Frios, when the user clicked to change the product, it returned the value Frios in the spinner class Alterproduct.class
Att.
Giovani Rodrigo
What is the difference in setting by position or value?
– Giovani Rodrigo
The method receives only the position that should be set, if you don’t know that position exactly you go through the list and compare the values by looking for the position. At the end you will always be passing a position which is what the method asks for as parameter.
– BrunoAgenor
For position, instead of saving the value of the selected imte as string, I should save as int value of the item position?
– Giovani Rodrigo
Better not, because if you need to change the list in the future you may have complications.
– BrunoAgenor