Bug con Android spinner en 2.2 relacionado con el arreglo de disposición

A continuación se muestra un enlace al error que estoy experimentando con mi aplicación de Android. En lugar de tratar de explicarlo a través de una enorme pared de texto, pensé que un simple video sería mucho más directo y más fácil de entender.

He estado golpeando mi cabeza contra una pared en este problema por un día y medio ahora. Sólo encontré que podría ser resuelto por el cambio de la disposición XML recientemente que hace absolutamente ningún sentido para mí. No tengo ni idea de cómo solucionarlo correctamente, o una forma de band-aid el problema ya que necesito los diseños anidados en mi aplicación.

Gracias a todos por su ayuda!

Aquí está el código:

import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; public class Builder extends Activity { private Spinner mCompSelect; private Spinner mNameSelect; private int[] mCompColorAsBuilt; private int mComponent; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.builder); mCompColorAsBuilt = new int[3]; //Attach our objects mCompSelect = (Spinner) findViewById(R.id.component); mNameSelect = (Spinner) findViewById(R.id.component_name); //Attach an adapter to the top spinner ArrayAdapter<CharSequence> a = ArrayAdapter.createFromResource(this, R.array.cc_components, android.R.layout.simple_spinner_item); a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mCompSelect.setAdapter(a); //Create a listener when the top spinner is clicked mCompSelect.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { //Save the position mComponent = position; //Create a new adapter to attach to the bottom spinner based on the position of the top spinner int resourceId = Builder.this.getResources().getIdentifier("component"+Integer.toString(mComponent)+"_color", "array", Builder.this.getPackageName()); ArrayAdapter<CharSequence> a = ArrayAdapter.createFromResource(Builder.this, resourceId, android.R.layout.simple_spinner_item); a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mNameSelect.setAdapter(a); //Set the position of the bottom spinner to the saved position mNameSelect.setSelection(mCompColorAsBuilt[mComponent]); } public void onNothingSelected(AdapterView<?> parent) { } }); //Attach an adapter to the bottom spinner int resourceId = this.getResources().getIdentifier("component"+Integer.toString(mComponent)+"_color", "array", this.getPackageName()); ArrayAdapter<CharSequence> b = ArrayAdapter.createFromResource(this, resourceId, android.R.layout.simple_spinner_item); b.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mNameSelect.setAdapter(b); mNameSelect.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { //Save the position of the bottom spinner mCompColorAsBuilt[mComponent] = position; } public void onNothingSelected(AdapterView<?> parent) { } }); } } 

XML

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Spinner android:id="@+id/component" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@+id/finish" android:drawSelectorOnTop="true" android:prompt="@string/component_spinner" /> <LinearLayout android:orientation="horizontal" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content" > <Spinner android:id="@+id/component_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:drawSelectorOnTop="true" android:prompt="@string/component_name_spinner" /> </LinearLayout> </RelativeLayout> 

Como hack, intenta invocar invalidate() en el Spinner afectado. En primer lugar, intente después de llamar a setSelection() . Si esto falla, intente usar postDelayed() en el Spinner para llamar a invalidate() un poco más tarde (por ejemplo, 50ms).

Además, le animo a crear un proyecto de demostración con dos actividades (o tal vez sólo una actividad con dos diseños) que ilustra este comportamiento y lo publica y una explicación a http://b.android.com .

  • Obtener la altura de un TextView
  • ¿Qué significa poner signo "$" antes de un parámetro en Java / Android?
  • Cómo cambiar la orientación de bloqueo en Android?
  • Combinación de celdas en Excel mediante Apache POI
  • Android httpclient.execute excepción
  • ¿Puedes tener #regions en Android / eclipse
  • Android: TextInputLayout no centrará la pista
  • Kryonet y Android
  • La consulta MMS sólo devuelve el tamaño del mensaje de los archivos adjuntos enviados
  • Android CookieManager
  • ¿Cómo se guardan las imágenes de Amazon S3 desde la cámara Android?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.