in the program I inflate several Spinners and add them to a layout. For each spinner I make an individual selection. This works fine if the Activity is created as usual - so every spinner gets his own selection. If the activity is created due to a rotation it will apply the value of the last spinner to all spinner and I watched that a onItemSelectedListener will be called multiple times. I am very desperate since that seems not very logic to me. Here is the code:
SpinnerTesterActivity.xml
public class SpinnerTesterActivity extends Activity {
public String[] array={"s0","s1","s2","s3","s4","s5","s6","s7","s8","s9"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("SPINNERTESTER", "REPAINT ACTIVITY");
LinearLayout layout=(LinearLayout)this.findViewById(R.id.parentLayout);
for (int i = 0 ; i<3; i++){
LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup reminderLayout = (ViewGroup) layoutInflater.inflate(R.layout.edit_item, null);
Spinner spinner = (Spinner) reminderLayout.findViewById(R.id.spinner);
spinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, array));
spinner.setSelection(i);
layout.addView(reminderLayout);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/parentLayout" >
</LinearLayout>
edit_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dip"
android:paddingTop="3dip" >
<Spinner
android:id="@+id/spinner"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />
</LinearLayout>