我正在尝试在自定义适配器中使用 AsuncTask。当我尝试使用
class UpdateProductVariantTask extends AsyncTask<String, String, Void> {
private ProgressDialog progressDialog = new ProgressDialog(context);
String result = "";
protected void onPreExecute() {
progressDialog.setCancelable(false);
progressDialog.setMessage("Please wait.....");
progressDialog.show();
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
UpdateProductVariantTask.this.cancel(true);
}
});
}
}
我收到这个错误:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
在线 progressDialog.show();
如何解决这个错误?
最佳答案
尝试使用 Activity 而不是上下文。
private ProgressDialog progressDialog = new ProgressDialog(activity);
关于android - 如何在自定义适配器中初始化 ProgressDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34837107/