0
我想按下按鈕後顯示一個對話框,但下面的代碼不執行並顯示FragmentDialog。提前致謝。Android - DialogFragment not Showing
//BackPress
public void onBackPressed() {
TestDialogFragment test= new TestDialogFragment();
test.newInstace();
// Showing Alert Message
Log.d("Video Backpressed", "sdfdf");
}
TestDialogFragment
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);
}
}
得到錯誤,先生,「在類型DialogFragment的方法秀(FragmentManager,字符串)不適用的參數(FragmentManager,字符串)」 – rahstame
是否使用'FragmentActivity'?然後使用'getSupportFragmentManager()' – Geros
是的,我使用FragmentActivity,它現在正在工作。你可以簡單解釋一下你的答案。然後我會接受你的決心。感謝您的答覆。美好的一天! – rahstame