Show dialog from fragment?

前端 未结 7 818
再見小時候
再見小時候 2020-11-30 19:17

I have some fragments that need to show a regular dialog. On these dialogs the user can choose a yes/no answer, and then the fragment should behave accordingly.

Now,

7条回答
  •  醉话见心
    2020-11-30 20:21

     public void showAlert(){
    
    
         AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
         LayoutInflater inflater = getActivity().getLayoutInflater();
         View alertDialogView = inflater.inflate(R.layout.test_dialog, null);
         alertDialog.setView(alertDialogView);
    
         TextView textDialog = (TextView) alertDialogView.findViewById(R.id.text_testDialogMsg);
         textDialog.setText(questionMissing);
    
         alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
                 dialog.cancel();
             }
         });
         alertDialog.show();
    
    }
    

    where .test_dialog is of xml custom

提交回复
热议问题