2
spinner
は、別のspinner selection
に基づいて作成されていません。何時間もこの問題を解決できませんでした。前もって感謝します。アンドロイド:別のスピナーの選択に基づいてスピナーを投入する
これは、あなたが、これはあなたを助けるonItemSelectedListner
yourMainSpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String spinnerValue = yourMainSpin.getSelectedItem().toString();
if (spinnerValue.equals("requierdString")) {
subSpinner.setAdapter(yourAdapter);
}else if (spinnerValue.equals("requierdString")){
subSpinner.setAdapter(yourAdapter);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
希望を使用して、選択した項目の値でそれを試してみて自分のコード
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, SPINNERCOUNTRY);
spinnerCountry = (MaterialBetterSpinner) findViewById(R.id.spinnerState);
spinnerCountry.setAdapter(adapter);
spinnerCity = (Spinner) findViewById(R.id.spinnerCity);
spinnerCountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) {
adapterView.getItemAtPosition(pos);
if (pos == 0) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter
.createFromResource(SpinnerStateCitySelectorActivity.this, R.array.city_Tamil_Nadu,
android.R.layout.simple_spinner_dropdown_item);
spinnerCity.setAdapter(adapter);
} else if (pos == 1) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter
.createFromResource(SpinnerStateCitySelectorActivity.this, R.array.city_Kerela,
android.R.layout.simple_spinner_dropdown_item);
spinnerCity.setAdapter(adapter);
} else if (pos == 2) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter
.createFromResource(SpinnerStateCitySelectorActivity.this, R.array.city_Karnataka,
android.R.layout.simple_spinner_dropdown_item);
spinnerCity.setAdapter(adapter);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});