【发布时间】:2017-04-30 17:47:35
【问题描述】:
我什至无法在异步任务本身上创建自定义对话框,所以我调用了一个方法来显示它,这是我的方法:
public void showCustomLocationDialog(String title) {
final Dialog customDialog = new Dialog(this);
customDialog.setContentView(R.layout.custom_location_dialog);
customDialog.setTitle(title);
if (!customDialog.isShowing()) {
// set the custom dialog components - title, ProgressBar and button
TextView text = (TextView) customDialog.findViewById(R.id.textView);
text.setText(title);
customDialog.show();
}else if (customDialog.isShowing())
{
customDialog.dismiss();
}
}
我得到的错误:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
....
我在这里所做的是在 onPreExecute 和 onPostExecute 上调用此方法。
我尝试在 PreExecute 上创建对话框,但是遇到了错误。尤其是“setContentView”。
如何在异步任务完成后关闭我的自定义对话框?
【问题讨论】:
-
当
AsyncTask完成时,onPostExecute函数被调用,所以你应该把你的customDialog.dismiss();放进去。