我在我的应用程序中添加了一个asynctask,因为它有很多要搜索的数据,但我在受保护的Void doInBackground中遇到错误,并且它说必须从UI线程调用Method getText(),当前推断的线程是worker。我的应用程序由具有editText和Spinner的对话框组成。请帮助我,并提前感谢。
doctorLocationEditText = (EditText)dialog.findViewById(R.id.doctorlocation);
doctorHospital = (Spinner) dialog.findViewById(R.id.spinnerdoctorhospital);
ArrayAdapter<String> hospitalAdapter = new ArrayAdapter<String>(Doctor.this,R.layout.spinner_layout, db.getAllHospitalName());
hospitalAdapter.setDropDownViewResource(R.layout.spinner_layout);
doctorHospital.setAdapter(hospitalAdapter);
Button button = (Button) dialog.findViewById(R.id.btndoctorsearch);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DoctorSearch().execute();
dialog.dismiss();
这是我的asynctask有错误
class DoctorSearch extends AsyncTask<Void, Void, Void> {
ProgressDialog Asycdialog = new ProgressDialog(Doctor.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
Asycdialog.setMessage("Loading...");
Asycdialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
GetSearchDoctor = dbhelper.getDoctorSearch(index2, doctorLocationEditText.getText().toString(), doctorHospital.getSelectedItem().toString());
return null;
}
@Override
protected void onPostExecute(Void result) {
lv3 = (ListView) findViewById(R.id.searchdoctor_list);
lv3.setAdapter(new ViewAdapterSearchDoctor());
super.onPostExecute(result);
Asycdialog.dismiss();
}
}