我有一个活动,在 AsyncTask 的帮助下,我使用 Spinner 从 WebService 调用中填充它。我的问题是,在 logcat 中,我可以看到所有ArrayAdapter<String>
项目,但是当我将此适配器提供给我的 Spinner 时,它不显示下拉列表项目。这是我的代码片段:
public static ArrayAdapter<String> adapter;
Spinner spnrCourseType;
spnrCourseType.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
new DownloadCourseTypesList().execute(training_id);
return true;
}
});
spnrCourseType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
ting("You Selected : " + adapter.getItem(arg2));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
/** Thread AsyncTask Class */
private class DownloadCourseTypesList extends AsyncTask<String,Void,ArrayList<String>> {
ProgressDialog progressDialog = new ProgressDialog(CorporateTrainingInquiryActivity.this);
protected void onPreExecute(){
actionBar.setProgressBarVisibility(View.VISIBLE);
progressDialog.setTitle("Course Types Loading..");
progressDialog.setMessage("Please Wait..");
progressDialog.show();
}
protected ArrayList<String> doInBackground(String... params) {
trainingList = new TrainingList(params[0]);
ArrayList<String> values = trainingList.getTrainingList();
// adapter = new ArrayAdapter<String>(CorporateTrainingInquiryActivity.this,android.R.layout.simple_spinner_item,values);
return values;
}
protected void onPostExecute(ArrayList<String> values) {
actionBar.setProgressBarVisibility(View.GONE);
adapter = new ArrayAdapter<String>(CorporateTrainingInquiryActivity.this,android.R.layout.simple_spinner_item,values);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.insert("Select Course Type",0);
spnrCourseType.setAdapter(adapter);
for(int i=0;i<adapter.getCount();i++){
System.out.println("Item in adapter at position : " + i + adapter.getItem(i));
}
adapter.notifyDataSetChanged();
if(progressDialog.isShowing()){
progressDialog.dismiss();
}
}
}
当我执行上述代码时,ProgressDialog 变得可见,并且只有第一项,即“选择课程类型”在 Spinner 本身上可见,但在下拉列表项中不可见。关于它的任何线索。从昨天开始,我就陷入了困境:(