我有这样的代码:
在按钮中单击我编写此代码:
new Loadiing().execute();
我创建的AsyncTask类,我的类看起来像:
public class Loadiing extends AsyncTask<Void,Void,Void>{
ProgressDialog d= new ProgressDialog(Main.this);
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
ProgressDialog.show(Main.this, "", "Loading");
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
**A method which returns some data in a arrayadapter and sets it;**
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
d.dismiss();
}
}
但它刚刚启动一个警告对话框,后台没有任何操作,对话框也没有被解雇,该怎么办?
答案 0 :(得分:2)
这应该是,
d.show();
而不是ProgressDialog.show(Main.this, "", "Loading");
更新:在您的情况下,
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
d.setTitle("Loading");
d.show();
}