【发布时间】:2016-11-14 09:30:31
【问题描述】:
我已经创建了一个 Util 类来像这样打开和关闭进度对话框
Utils.java
public class Utils {
private static Utils util;
private Typeface typeface;
private ProgressDialog progressDialog;
public static Utils getInstance(){
if(util == null){
util = new Utils();
}
return util;
}
public void showProgressDialog(Activity activity){
if(progressDialog != null && progressDialog.isShowing()){
return;
}
if(progressDialog == null ) {
progressDialog = new ProgressDialog(activity);
}
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCancelable(false);
progressDialog.show();
}
public void closeProgressDialog(){
try {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
}catch(Exception e){
e.printStackTrace();
}
}
}
然后我在加载数据之前调用 showProgressDialog 并在加载数据之后调用 closeProgressDialog。像这样
活动代码
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_dashboard,container,false);
activity = getActivity();
ButterKnife.bind(this,view);
init();
return view;
}
private void init() {
Utils.getInstance().showProgressDialog(activity);
getPatientsList();
//in response i am calling closeProgressDialog();
}
public void onPatientListResponse(String response){
Utils.getInstance().closeProgressDialog(); // raises exception here
}
但它在 closeProgressDialog() 中引发异常;
java.lang.IllegalArgumentException: View=com.android.internal.policy.PhoneWindow$DecorView{f7fd12e V.E...... R......D 0,0-1024,232} not attached to window manager
【问题讨论】:
标签: android performance progressdialog