//Create spinner and I save the spinner position in a public variable

Spinner s = (Spinner) findViewById(R.id.lstForma);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.vetor_forma, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
s.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> parent, View v, int posicao, long id) 
{

strForma = parent.getItemAtPosition(posicao).toString();
strFormaID = posicao; //here i save the spinner position in a public variable

if (strForma.equals("Outra")) {
edtFormaOutros.setEnabled(true);
edtFormaOutros.requestFocus();
}
else {
edtFormaOutros.setEnabled(false);
}

}//Fim do método onItemSelected()

public void onNothingSelected(AdapterView<?> arg0) {

}//Fim do método onNothingSelected()

}
);//Fim do método setOnItemSelectedListener()

2 step -> On method… 
@Override    
protected void onSaveInstanceState( Bundle savedInstanceState){
super.onSaveInstanceState(savedInstanceState);

//Save the spinner position in a savedInstaceState variable… se the code below:
savedInstanceState.putInt("strFormaID" , strFormaID);
3 step -> On method
@Override 
protected void onRestoreInstanceState( Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState); 
//Return the spinner state to the public variable
strFormaID=savedInstanceState.getInt("strFormaID");
//recreate the spinner and set the state with public variable strFormaIF
Spinner s = (Spinner) findViewById(R.id.lstForma);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.vetor_forma, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);

s.setSelection(strFormaID); //here i set the position 
Easy! now you can rotate as fast as you can, and the state will persist!
Reinaldo Holanda Carlos 
www.flavorsys.com.br

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to