【发布时间】:2012-06-08 02:46:30
【问题描述】:
我有一个按钮,当我点击它时,我会加载其他 Activity,在 onCreate 中我调用一个方法,用来自 Web 服务的数据填充微调器。
好吧,当我单击此按钮时,屏幕保持“冻结”状态,然后显示活动。所以,我认为向用户显示一个进度对话框可能是件好事,并在获得 Web Service 的返回后,结束进度对话框。
我尝试使用 Handler,现在我尝试使用 AsyncTask,但是,得到 NullPointerException,因为我的程序在调用 Web 服务之前填充微调器。
private void fillSpinner(){
//runWebService();
new CallWebServiceAsyncTask().execute(null);
mAdapter = new PlanesAdapter(this, allPlanes);
mList.setAdapter(mAdapter);
}
class CallWebServiceAsyncTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(PlanesActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
@Override
protected Void doInBackground(Void... v) {
runWebService();
return null;
}
@Override
protected void onPostExecute(Void result) {
progressDialog.dismiss();
}
}
【问题讨论】:
标签: android nullpointerexception spinner progressdialog