下面是我的代码:工作正常,但对话框没有显示.Dialog应该打开ASyncTask启动并解除end.how是可能的吗?
Public class RootClass
{
public ProgressDialog dialog;
public List methodA(String a)
----
----
Class childClass extends AsyncTask<Void,Void,Void>
{
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(RootClass.this,"Please wait", "Message");
}
@Override
protected Void doInBackground(Void... params) {
----
---
---
List<String> B=methodA(String a);
-----
-----
}
@Override
protected void onPostExecute(Void result) {
dialog.dismiss();
return;
}
}
}</pre>
答案 0 :(得分:0)
您的RootClass应该扩展Activity类
public class RootClass extends Activity
答案 1 :(得分:0)
。在你要启动异步任务的那个事件上写
dialog = ProgressDialog.show(RootClass.this,"Please wait", "Message");
你无法在doiin backgroung()方法中更新ui,
以及稍后onPostExecute(),dialog.dissmiss;。
答案 2 :(得分:-1)
而不是使用 - public ProgressDialog dialog;
尝试使用 - public Dialog process;
并在Async taks中使用此代码
protected void onPreExecute()
{
progress = ProgressDialog.show(YourActivity.this, "Please wait",
"Loading..", true);
}
和
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (progress.isShowing()) {
progress.dismiss();
}
希望这有帮助!