第一个项目在 xml ( <string-array>
) 中定义,但第二个项目应根据第一个项目上选择的内容呈现不同的项目字符串数组...
秒的可能字符串数组是使用AsyncTask
(这部分正在工作)从 Web 服务中获取的。在我的onPostExecute(Void result)
我有这个:
private class GetInfoTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog dialog = new ProgressDialog(StateTabActivity.this);
//...
@Override
protected void onPostExecute(Void result) {
Log.d("StateTabActivity","onPostExecute");
sectorsArray = getSectorsName(); // sectorsArray is an array of strings
roomsArray = getRoomsName(); // roomsArray is an array of strings
subcategorySpinnerAdapter = new ArrayAdapter<String>(StateTabActivity.this, R.layout.my_spinner,sectorsArray);
subcategorySpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
subCategorySpinner.setAdapter(subcategorySpinnerAdapter);
dialog.dismiss();
}
}
在onCreate()
我的活动中,我有:
Spinner categorySpinner = (Spinner) findViewById(R.id.statetab_category_spinner);
ArrayAdapter<String> categorySpinnerAdapter = new ArrayAdapter<String>(this, R.layout.my_spinner,getResources().getStringArray(R.array.array_category));
categorySpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
categorySpinner.setAdapter(categorySpinnerAdapter);
subCategorySpinner = (Spinner) findViewById(R.id.statetab_subcategory_spinner);
categorySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Log.d("StateTabActivity","in onitemselected");
switch (arg2) {
case 0:
//I want to set here the items of sectorsArray to be displayed on the second spinner (subCategorySpinner)
break;
case 1:
//I want to set here the items of roomsArray to be displayed on the second spinner (subCategorySpinner)
break;
default:
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
所以我的问题是:我应该怎么做才能将正确的数组绑定到第二个微调器,根据第一个微调器上的选择?