我想在按下后退按钮时显示一个对话框,但下面的代码没有执行并显示 FragmentDialog。提前致谢。
//BackPress
public void onBackPressed() {
TestDialogFragment test= new TestDialogFragment();
test.newInstace();
// Showing Alert Message
Log.d("Video Backpressed", "sdfdf");
}
测试对话片段
public static class TestDialogFragment extends DialogFragment {
public static DialogFragment newInstace() {
DialogFragment dialogFragment = new TestDialogFragment();
return dialogFragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("TestDialogFragment");
builder.setView(getContentView());
Dialog dialog = builder.create();
return dialog;
}
private View getContentView() {
LayoutInflater inflater = getActivity().getLayoutInflater();
return inflater.inflate(R.layout.dialog_fragment, null);
}
}