2010-12-28 18 views
5

Aşağıda Android uygulamam ile yaşadığım hatanın bir bağlantıdır. Büyük bir metin duvarı ile açıklamaya çalışmak yerine, basit bir videonun daha doğrudan ve anlaşılması daha kolay olacağını düşündüm. Düzeni düzenleme ile ilgili 2.2 2.2 inç Android çevirici ile Hata

http://www.youtube.com/watch?v=9V3v854894g

Şimdi bir gün için bu soruna bir buçuk üzerinde kafamı duvara dayak oldum. Sadece son zamanlarda XML düzenini değiştirerek çözülebildiğini öğrendim, bu da bana kesinlikle hiçbir anlam ifade etmiyor. Uygulamamda iç içe geçmiş düzenlere ihtiyaç duyduğumdan sorunu nasıl düzeltebileceğimi ya da sorunu çözmeye yardım etmenin bir yolunu bilmiyorum.

Yardımlarınız için herkese teşekkürler! İşte

kod şudur: Bir hack olarak

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> 

cevap

1

, etkilenen Spinner üzerinde invalidate() arayarak deneyin. Önce, setSelection()'u aradıktan sonra deneyin. Bu başarısız olursa, Spinner üzerinde postDelayed() kullanmayı invalidate() biraz sonra (ör. 50ms) arayın. Ayrıca, bu davranışı gösteren iki eylem (veya belki de iki düzen içeren bir etkinlik) içeren bir tanıtım projesi oluşturmanızı ve bunu http://b.android.com numaralı açıklamaya göndermenizi öneririm.

+0

Her ikisini de denedim ve maalesef aynı sonuçla sona erdi. Soruna yardım etmek için bana bir fikir verdin. Alt döndürücüyü yanlış değere ayarlayabilir ve doğru değere geri yüklemek için bir postDelayed() kullanabilirim. Güzel değil ama şimdilik hile yapmış gibi görünüyor. Bu hafta sonu birlikte bir hata raporu koyacağım. Yardımın için teşekkürler! – user432209

İlgili konular