2 [在此圖像中,當我點擊項目時顯示微調項值並且沒有顯示項目時顯示,並且當我選擇項目沒有顯示在微調控件上,但值正在服務器上]如何將一個微調項目與第二個微調項目相關聯項目
1 [這是哪裏出了第二圖像微調項目]
我想要實現,我用了兩個微調一個代碼,並有將在下面的代碼給出,現在我想,如果我選擇沒有在第一微調項目那麼第二個微調器將只顯示沒有項目,如果我在第一個微調器中選擇1,則第二個微調器將只顯示沒有項目和1個項目。誰能幫我謝謝你提前
<Spinner
android:background="@drawable/spinner_back"
android:id="@+id/NumberOfBro"
android:layout_width="350dp"
android:layout_height="50dp"
android:entries="@array/no_of_brothers"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"/>
<Spinner
android:background="@drawable/spinner_back"
android:id="@+id/NumberOfMarriedBrother"
android:layout_width="350dp"
android:layout_height="50dp"
android:entries="@array/no_of_married_Brothers"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_below="@+id/NumberOfBro"/>
<string-array name="no_of_brothers">
<item>Select Number of Brothers</item>
<item>None</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>4+</item>
</string-array>
<string-array name="no_of_married_Brothers">
<item>Select Number of Married Brother</item>
<item>None</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>4+</item>
</string-array>
這是我用此微調
Spinner noOfBro = (Spinner) findViewById(R.id.noOfBro);
Spinner noOfMBros = (Spinner) findViewById(R.id.noOfMBros);
noOfBro.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> adapterView, View view,
int position, long l) {
String[]resList=getResources().getStringArray
(R.array.no_of_merried_brothers);
String[] spList = new String[position + 1];
for (int i = 0; i <= position; i++) {
spList[i] = resList[i];
}
ArrayAdapter<String> adapter = new ArrayAdapter<>
(getApplicationContext(),
android.R.layout.simple_spinner_item, spList);
noOfMBros.setAdapter(adapter);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
後,你已經嘗試過你的java代碼.. –
請檢查我編輯的代碼。 –