0
我已經創建了一個類,並在佈局中添加了兩個微調器。父母兒童微調器
目標:如果您從第一個微調器中選擇任何項目,它將更改第二個微調器的內容。我的電話是onCreate()(onItemSelected(spinnercategoryl, spinnerEnterprisel, x, i);)
。問題是,當我從第一個選擇任何項目時,它會更改第二個項目的內容,但是如果我需要從第二個項目中選擇任何項目,那麼它將不會顯示爲選定項目。
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
// TODO Auto-generated method stub
Spinner spinnerEnterprisel = (Spinner) findViewById(R.id.spinner_enterprise_folding_inserter);
Spinner spinnercategoryl = (Spinner) findViewById(R.id.spinner_categories);
switch (spinnercategoryl.getSelectedItemPosition()) {
case 0:
ArrayAdapter<CharSequence> adapterDatal = ArrayAdapter
.createFromResource(this,
R.array.enterprise_folding_inserter,
android.R.layout.simple_spinner_item);
adapterDatal
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerEnterprisel.setAdapter(adapterDatal);
break;
case 1:
ArrayAdapter<CharSequence> adapterData1 = ArrayAdapter
.createFromResource(this, R.array.enterprise_sorters,
android.R.layout.simple_spinner_item);
adapterData1
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerEnterprisel.setAdapter(adapterData1);
break;
case 2:
ArrayAdapter<CharSequence> adapterData2 = ArrayAdapter
.createFromResource(this, R.array.Softwares,
android.R.layout.simple_spinner_item);
adapterData2
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerEnterprisel.setAdapter(adapterData2);
break;
case 3:
ArrayAdapter<CharSequence> adapterData3 = ArrayAdapter
.createFromResource(this, R.array.workflow,
android.R.layout.simple_spinner_item);
adapterData3
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerEnterprisel.setAdapter(adapterData3);
break;
}
spinnerEnterprisel.setOnItemSelectedListener(enterprise.this);
spinnercategoryl.setOnItemSelectedListener(enterprise.this);
// Spinner spinnerEnterprisel1 = (Spinner)
// findViewById(R.id.spinner_enterprise_folding_inserter);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}`
非常感謝你,你是對的。 :)它現在工作正常。 – ADAM