5
다음은 Android 애플리케이션에서 발생하는 버그에 대한 링크입니다. 거대한 텍스트 벽을 통해 설명하려고하는 것이 아니라 단순한 비디오가 훨씬 더 직접적이고 이해하기 쉬울 것이라고 생각했습니다. 레이아웃 구성과 관련된 2.2의 Android 스피너가있는 버그
http://www.youtube.com/watch?v=9V3v854894g
는 지금 하루 동안이 문제에 절반을 벽에 내 머리를 때리고 있었어요. 나는 단지 XML 레이아웃을 최근에 변경하여 해결할 수 있다는 것을 발견했는데, 이는 나에게 전혀 의미가 없습니다. 응용 프로그램에서 중첩 된 레이아웃이 필요하기 때문에 제대로 수정하는 방법이나 문제를 반창으로 해결할 방법이 없습니다.모두에게 감사드립니다. 여기
코드입니다 : 해킹으로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>
나는 둘 다 시도했지만 불행하게도 같은 결과로 끝났다. 당신은 나에게 문제를 반창고하기위한 아이디어를주었습니다. 하단 스피너를 잘못된 값으로 설정하고 postDelayed()를 사용하여 올바른 값으로 되돌릴 수 있습니다. 그것은 꽤 아니지만 그것은 지금 트릭을 한 것으로 보인다. 이번 주말에 버그 보고서를 작성하겠습니다. 도와 줘서 고마워! – user432209