这里添加了 2 个微调器。如果我选择特定的 item1 和 item2,则必须显示特定的图像。例如,如果选择了“Gujarat”和“Gandhinagr”,则必须显示图像 abc.png。请帮帮我。
public class MainActivity extends Activity implements OnItemSelectedListener {
private String[] INDIAN_STATE = { "Gujarat", "Andra Pradesh",
"Arunachal Pradesh", "Assam", "Bihar", "Chhattisgarh", "Goa",
"Haryana", "Himachal Pradesh", "Jammu and Kashmir", "Jharkhand",
"Karnataka", "Kerala", "Madya Pradesh", "Maharashtra", "Manipur",
"Meghalaya", "Mizoram", "Nagaland", "Orissa", "Punjab",
"Rajasthan", "Sikkim", "Tamil Nadu", "Tripura", "Uttaranchal",
"Uttar Pradesh", "West Bengal" };
private String[] INDIAN_STATE_CAPITAL = { "Gandhinagar", "Hyderabad",
"Itangar", "Dispur", "Patna", "Raipur", "Panaji", "Chandigarh",
"Shimla", "Srinagar and Jammu", "Ranchi", "Bangalore",
"Thiruvananthapuram", "Bhopal", "Mumbai", "Imphal", "Shillong",
"Aizawi", "Kohima", "Bhubaneshwar", "Chandigarh", "Jaipur",
"Gangtok", "Chennai", "Agartala", "Dehradun", "Lucknow", "Kolkata" };
Spinner spinnerState, spinnerCapital;
TextView tvState, tvCapital;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println(INDIAN_STATE.length);
System.out.println(INDIAN_STATE_CAPITAL.length);
tvState = (TextView) findViewById(R.id.mystate);
tvCapital = (TextView) findViewById(R.id.mystatescapital);
spinnerState = (Spinner) findViewById(R.id.spinnerstate);
spinnerCapital = (Spinner) findViewById(R.id.spinnercapital);
ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, INDIAN_STATE);
adapter_state
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerState.setAdapter(adapter_state);
ArrayAdapter<String> adapter_state_capital = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item,
INDIAN_STATE_CAPITAL);
adapter_state_capital
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCapital.setAdapter(adapter_state_capital);
spinnerState.setOnItemSelectedListener(this);
spinnerCapital.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
spinnerState.setSelection(position);
spinnerCapital.setSelection(position);
String myState = (String) spinnerState.getSelectedItem();
String myStatesCapital = (String) spinnerCapital.getSelectedItem();
tvState.setText("My State is " + myState);
tvCapital.setText("My State is " + myState + ".And its Capital is "
+ myStatesCapital);
}
public void onNothingSelected(AdapterView<?> parent) {
}
}