我有一個顯示三個旋轉器的android活動。同樣的三個人有相同的信息可供選擇,因爲你應該選擇五件中的三件。我想要做的是根據現在選擇的內容顯示信息。例如,如果在第一個微調中我選擇了「硬幣」,我不希望能夠在左邊的兩個微調中選擇硬幣,如果在第二個微調中選擇了「Capital」,我不想顯示大寫和硬幣最後一個。如何保存旋轉器之間的顯示信息android
這是我對活動的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#449def"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/typeDrinks"
style="@style/textStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select three question for ask"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/LinearLayout" >
<Spinner
android:id="@+id/spinner_type1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="8sp"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/textRangeOfPrices"
style="@style/textStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#449def"
android:gravity="center"
android:text="Select another one"
android:textSize="22sp" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textRangeOfPrices"
android:orientation="horizontal" >
<Spinner
android:id="@+id/spinner_type2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="8sp"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/textViewDistance"
style="@style/textStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#449def"
android:gravity="center"
android:text="The last one"
android:textSize="22sp" />
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewDistance"
android:orientation="horizontal" >
<Spinner
android:id="@+id/spinner_type3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="8sp"
android:gravity="center" />
</LinearLayout>
<Button
android:id="@+id/buttonGenerateRestaurant"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@layout/blue_button"
android:onClick="generateQuery"
android:text="Generate" />
</RelativeLayout>
這是我到目前爲止的代碼。有了這個代碼出現在三個紡紗相同的信息,您可以選擇三次同樣的事情
/*
* this part of the code is for displaying the spinner with the selected
* choice
*/
spinnerType1 = (Spinner) findViewById(R.id.spinner_type1);
spinnerType2 = (Spinner) findViewById(R.id.spinner_type2);
spinnerType3 = (Spinner) findViewById(R.id.spinner_type3);
ArrayAdapter<CharSequence> adapterType1 = ArrayAdapter
.createFromResource(this, R.array.range_types,
android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> adapterType2 = ArrayAdapter
.createFromResource(this, R.array.range_types2,
android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> adapterType3 = ArrayAdapter
.createFromResource(this, R.array.range_type3,
android.R.layout.simple_spinner_item);
adapterType1
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapterType2
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapterType3
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerType1.setAdapter(adapterType1);
spinnerType2.setAdapter(adapterType2);
spinnerType3.setAdapter(adapterType3);
spinnerType1.setOnItemSelectedListener(this);
spinnerType2.setOnItemSelectedListener(this);
spinnerType3.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
mType1 = (String) spinnerType1.getSelectedItem().toString();
mType2 = (String) spinnerType2.getSelectedItem().toString();
mType3 = (String) spinnerType3.getSelectedItem().toString();
}
這是我對範圍
<string-array name="range_types">
<item>Complete Name</item>
<item>Coin</item>
<item>Capital</item>
<item>Area(Km)</item>
<item>Political system</item>
</string-array>
<string-array name="range_types2">
<item>Complete Name</item>
<item>Coin</item>
<item>Capital</item>
<item>Area(Km)</item>
<item>Political system</item>
</string-array>
<string-array name="range_type3">
<item>Complete Name</item>
<item>Coin</item>
<item>Capital</item>
<item>Area(Km)</item>
<item>Political system</item>
</string-array>
我一直在尋找谷歌和stackoverflow,但我沒有找到確切的我在找什麼,或者只是我不知道如何正確地問它
非常感謝!