0
此處添加2個微調器。如果我選擇特定的item1和item2,則必須顯示特定的圖像。例如,如果選擇「Gujarat」和「Gandhinagr」,則必須顯示圖像abc.png。 Plz幫助我。如果在2個微調中選擇了兩個項目,則圖像必須以可繪製形式顯示
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) {
}
}