我试图通过setselected(pos)将值设置为微调器,它适用于某些微调器但不适用于所有微调器。这是我的代码,我试图设置值。
ArrayAdapter<CharSequence> adapterItem = ArrayAdapter.createFromResource(this,
R.array.Item, android.R.layout.simple_spinner_item);
adapterItem.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
edmORdelOF.setAdapter(adapterItem);
System.out.println(profile.getEdmORdelOF()+"....getPosition..........."+adapterItem.getPosition(profile.getEdmORdelOF()));
edmORdelOF.setSelection(adapterItem.getPosition(profile.getEdmORdelOF()));
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.Org_type, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
org_type.setAdapter(adapter);
System.out.println(profile.getD_org_type()+"....getPosition..........."+adapter.getPosition(profile.getD_org_type()));
org_type.setSelection(adapter.getPosition(profile.getD_org_type()));
ArrayAdapter<CharSequence> adapterCountry = ArrayAdapter.createFromResource(this,
R.array.Country, android.R.layout.simple_spinner_item);
adapterCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
country.setAdapter(adapterCountry);
System.out.println(profile.getD_country()+"....getPosition..........."+adapterCountry.getPosition(profile.getD_country()));
country.setSelection(adapterCountry.getPosition(profile.getD_country()));
// this part doesn't work properly.
ArrayAdapter<CharSequence> adpState = ArrayAdapter.createFromResource(this,
R.array.India_States, android.R.layout.simple_spinner_item);
adpState.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
state.setAdapter(adpState);
System.out.println(profile.getD_state()+"....getPosition..........."+adpState.getPosition(profile.getD_state()));
state.setSelection(adpState.getPosition(profile.getD_state()));
if(state.getSelectedItem().toString().equalsIgnoreCase("Maharashtra"))
{
ArrayAdapter<CharSequence> adapterCity = ArrayAdapter.createFromResource(this,
R.array.Maharashtra_city, android.R.layout.simple_spinner_item);
adapterCity.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
District.setAdapter(adapterCity);
System.out.println(profile.getD_city()+"....getPosition..........."+adapterCity.getPosition(profile.getD_city()));
District.setSelection(adapterCity.getPosition(profile.getD_city()));
}
else if(state.getSelectedItem().toString().equalsIgnoreCase("karnataka"))
{
ArrayAdapter<CharSequence> adapterCity = ArrayAdapter.createFromResource(this,
R.array.Karnataka_District, android.R.layout.simple_spinner_item);
adapterCity.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
District.setAdapter(adapterCity);
System.out.println(profile.getD_city()+"....getPosition..........."+adapterCity.getPosition(profile.getD_city()));
District.setSelection(adapterCity.getPosition(profile.getD_city()));
}
else if(state.getSelectedItem().toString().equalsIgnoreCase("Goa"))
{
ArrayAdapter<CharSequence> adapterCity = ArrayAdapter.createFromResource(this,
R.array.goa_District, android.R.layout.simple_spinner_item);
adapterCity.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
District.setAdapter(adapterCity);
System.out.println(profile.getD_city()+"....getPosition..........."+adapterCity.getPosition(profile.getD_city()));
District.setSelection(adapterCity.getPosition(profile.getD_city()));
}
taluka = (Spinner) findViewById(R.id.Updatesp_sign_up_taluka);
ArrayAdapter<CharSequence> adaptertaluka = ArrayAdapter.createFromResource(this,
R.array.Ratnagiri_taluka, android.R.layout.simple_spinner_item);
adaptertaluka.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
taluka.setAdapter(adaptertaluka);
adaptertaluka.notifyDataSetChanged();
System.out.println(profile.getD_district()+"....getPosition..........."+adaptertaluka.getPosition(profile.getD_district()));
taluka.setSelection(adaptertaluka.getPosition(profile.getD_district()));
在这段代码中,它适用于所有微调器,除非他声明。请帮助我。我没有得到任何解决这个问题的方法。