What I am trying to do is for a user to select an element through a spinner, I save that element through the position and what I want is that when the user returns to edit the spinner he will be shown the one he marked first.
I leave here part of the code, statements:
private Spinner spinnerSeason;
private int season = 0;
private String[] Seasons = new String[] {
"Estacion",
"Indiferente",
"Invierno",
"Primavera",
"Verano",
"Otoño"
};
This would fit into the onCreate of the activity:
ArrayAdapter<String> spinnerArrayAdapterSeason = new ArrayAdapter<String>(
this,android.R.layout.simple_spinner_item,Seasons);
// Specify the layout to use when the list of choices appears
spinnerArrayAdapterSeason.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner
spinnerSeason.setAdapter(spinnerArrayAdapterSeason);
spinnerSeason.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
case R.id.spinnerSeason:
//tv.setText(tv.getText() + parent.getItemAtPosition(position).toString());
season = position;
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
//Another interface callback
}
});
Initialize the spinner:
spinnerSeason = (Spinner) findViewById(R.id.spinnerSeason);
This is where I should load the spinner element that the user previously set. From a method, I tell it to run if the user is editing, but does not load the one that the user frames but the first one of the vector.
spinnerSeason.setVerticalScrollbarPosition(season);
season has the value that the user previously set. fails the method of the Spinner class.