在我的活动中,有两个spinners
-perfix spinner
和性别spinner
。
我想做 - 当我选择性别时 - 女性它应该反映前缀微调中女性的前缀。我该怎么办?
性别的微调:
spnrGenderList=new ArrayList<>();
spnrGenderList.add("Male");
spnrGenderList.add("Female");
Spinner for Prefix
spnrPrefixList=new ArrayList<>();
spnrPrefixList.add(getResources().getString(R.string.mr));
spnrPrefixList.add(getResources().getString(R.string.mrs));
spnrPrefixList.add(getResources().getString(R.string.ms));
spnrPrefixList.add(getResources().getString(R.string.miss));
答案 0 :(得分:0)
您可以使用setOnItemSelectedListener
视图中的Spinner
来实现这一目标。
final List<String> spnrGenderList = new ArrayList<>();
spnrGenderList.add("Male");
spnrGenderList.add("Female");
final List<String> spnrPrefixList = new ArrayList<>();
genderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = parent.getItemAtPosition(position).toString();
spnrPrefixList.clear();
if (selectedItem.equals(spnrGenderList.get(0))) {
spnrPrefixList.add(getResources().getString(R.string.mr));
} else {
spnrPrefixList.add(getResources().getString(R.string.mrs));
spnrPrefixList.add(getResources().getString(R.string.ms));
spnrPrefixList.add(getResources().getString(R.string.miss));
}
prefixSpinnerAdapter.notifyDataSetChanged();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});