最后,解决了它。这是代码。我刚刚在第一个微调器的setOnItemSelectedListner上添加了第二个微调器的方法。现在我可以在第一个微调器中选择一个值,相应的值将来到第二个微调器,就像我在第一个微调器中有大学一样,当我在第一个微调器中选择一个大学时,第二个微调器将自动给出对应于第一个微调器的值
mSpinnerModel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedModel = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), "Selected Model: " + selectedModel, Toast.LENGTH_LONG).show();
//method for second spinner
String sp1=String.valueOf(mSpinnerModel.getSelectedItem());
if(sp1.contentEquals("College1")){
List<String> list = new ArrayList<String>();
list.add("MAHARANI UNIVERSITY ");
list.add("MANIPAL ");
list.add("ITM UNIVERSITY ");
list.add("UNIVERSITY1");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_item,list);
mSpinnerMake.setAdapter(dataAdapter);
}
selectedMake = parent.getItemAtPosition(position).toString();
if(sp1.contentEquals("College2")){
List<String> list = new ArrayList<String>();
list.add("ITM UNIVERSITY");
list.add("UNIVERSITY2");
list.add("UNIVERSITY3");
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_dropdown_item,list);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.notifyDataSetChanged();
mSpinnerMake.setAdapter(dataAdapter2);
}
if(sp1.contentEquals("College3")){
List<String> list = new ArrayList<String>();
list.add("MANIPAL ");
list.add("UNIVERSITY4");
list.add("UNIVERSITY5");
ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_dropdown_item,list);
dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter3.notifyDataSetChanged();
mSpinnerMake.setAdapter(dataAdapter3);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});