I have a simple program where I set a spinner to a position. I then call a second module and when I return, I reset the spinner. The spinner display does not display the spinner value. When you tap the spinner, it IS pointing to the correct value, but it displays an incorrect value. In fact, it actually steps down.
I wrote the following simple program to demonstrate. This only happens when the form has a spinner within either a Linearlayout or TableLayout with at lease 1 other element.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent" android:layout_height="200dp"
android:text="Main Form" />
<LinearLayout android:id="@+id/widget43"
android:layout_width="320dp" android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn" android:text="Button" android:textSize="16sp"
android:layout_width="160dp" android:layout_height="40dp" />
<Spinner
android:id="@+id/btnFour" android:textSize="16sp"
android:layout_width="160dp" android:layout_height="40dp" />
</LinearLayout>
</LinearLayout>
next.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/id1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
/>
</LinearLayout>
main.java
package tt.zzz;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
public class main extends Activity {
@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
fillSpinner();
Button btnGo = (Button) findViewById(R.id.btn);
btnGo.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) { Go(); } });
}
void Go() {
Intent i = new Intent(this, next.class );
startActivityForResult( i, 0 );
}
public void fillSpinner(){
Spinner spin_test = (Spinner) findViewById( R.id.btnFour );
ArrayAdapter<CharSequence> myAdapter =
new ArrayAdapter<CharSequence>(
this,
android.R.layout.simple_spinner_item
);
myAdapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
myAdapter.add("Option 1" );
myAdapter.add("Option 2" );
myAdapter.add("Option 3" );
spin_test.setAdapter(myAdapter);
spin_test.setSelection(1);
spin_test.setOnItemSelectedListener(
new Spinner.OnItemSelectedListener(){
public void onItemSelected(AdapterView<?>
arg0,View arg1,int arg2,long arg3){
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillSpinner();
}
}
next.java
package tt.zzz;
import android.app.Activity;
import android.os.Bundle;
public class next extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
}
}