我正尝试在我的应用中使用“ Two”微调器,其中第二个微调器值将基于第一个微调器位置,因此将从第二个微调器位置获得的值将使用
检索 item = adapterView.getItemAtPosition(position).toString();
及更高版本将被上传到Firebase数据库。
但是我无法根据第一个微调器填充第二个微调器。第一个微调程序加载正常,但是当我在第一个微调程序中选择任何选项时,第二个微调程序始终为空或没有任何数据可供选择。
这是我的代码
spinner_group = (Spinner) findViewById(R.id.spinner_group);
//implementing OnItemSelectedListener (need to override the method)
group_Array = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
group_Array.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_group.setAdapter(group_Array);
group_Array.add("Select your Group");
group_Array.add("Bangladesh");
group_Array.add("India");
group_Array.add("USA");
group_Array.add("Canada");
group_Array.setNotifyOnChange(true);
spinner_group.setSelection(0);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
subject_Array = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
subject_Array.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(subject_Array);
spinner.setActivated(false);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
item = adapterView.getItemAtPosition(position).toString();
count = position;
if (position == 0)
return;
Toast.makeText(adapterView.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
int group_spinner_position = spinner_group.getSelectedItemPosition();
switch (group_spinner_position){
case 0:
//fill data for second spinner
fillBangladeshDivision();
break;
case 1:
//fill data for second spinner
fillIndiaDivision();
break;
case 2:
//fill data for second spinner
fillUSADivision();
break;
case 3:
//fill data for second spinner
fillCanadaDivision();
break;
}
}
private void fillBangladeshDivision() {
subject_Array.clear();
subject_Array.add("MSC Physics");
subject_Array.add("MSC Chemistry");
subject_Array.notifyDataSetChanged();
}
private void fillIndiaDivision() {
subject_Array.clear();
subject_Array.add("MSC Biology");
subject_Array.add("MSC Geology");
subject_Array.notifyDataSetChanged();
}
private void fillUSADivision() {
subject_Array.clear();
subject_Array.add("BBS|BBA");
subject_Array.add("CA");
subject_Array.notifyDataSetChanged();
}
private void fillCanadaDivision(){
subject_Array.clear();
subject_Array.add("Bachelor");
subject_Array.add("BBS|BBA");
subject_Array.notifyDataSetChanged();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
请帮助。 预先感谢。