spinner
没有基于另一个spinner selection
进行填充,我已经使用了几个小时,仍然无法解决问题, LOGCAT中没有错误。提前谢谢。
这是我的代码
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) {
}
});
答案 0 :(得分:3)
您可以使用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) {
}
});
希望这会帮助你。
答案 1 :(得分:1)
用户onItemClickListener
代替setOnItemSelectedListener