Lux*_*ode 18 android android-fragments
我正在使用ProgressDialog托管作为Fragment.即使我将其设置为ProgressDialog不可取消,BACK按钮仍然可以Fragment从堆栈中删除它.我的内部类看起来像这样:
public static class ProgressDialogFragment extends DialogFragment {
private DialogStyle dialogStyle;
public static ProgressDialogFragment newInstance(String title, String message) {
ProgressDialogFragment fragment = new ProgressDialogFragment();
Bundle args = new Bundle();
args.putString("title", title);
args.putString("message", message);
fragment.setArguments(args);
return fragment;
}
public void setDialogStyle(DialogStyle dialogStyle) {
this.dialogStyle = dialogStyle;
}
@Override
public ProgressDialog onCreateDialog(Bundle savedInstanceState) {
String title = getArguments().getString("title");
String message = getArguments().getString("message");
ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle(title);
progressDialog.setMessage(message);
if(dialogStyle!=null) {
switch (dialogStyle) {
case CANCELABLE:
progressDialog.setCancelable(true);
break;
case NON_CANCELABLE:
progressDialog.setCancelable(false);
break;
}
} else {
progressDialog.setCancelable(false);
}
progressDialog.show();
return progressDialog;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我公开的方法是:
public void showProgressDialog(String title, String message, DialogStyle dialogStyle) {
Fragment prev = fragmentManager.findFragmentByTag("progress dialog");
if(prev!=null) {
ft.remove(prev);
}
ft.addToBackStack(null);
DialogFragment newFragment = ProgressDialogFragment.newInstance(title, message);
((ProgressDialogFragment)newFragment).setDialogStyle(dialogStyle);
newFragment.show(fragmentManager, "progress dialog");
}
Run Code Online (Sandbox Code Playgroud)
所以这里显而易见的混乱是BACK按钮删除了ProgressDialog因为它被管理为a Fragment.那么我怎样才能使它Dialog不被取消?
尝试类似的东西似乎很奇怪:
@Override
public void onBackPressed() {
if(fragmentManager.fragmentManager.findFragmentByTag("progress dialog")!=null) {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17480 次 |
| 最近记录: |