简体   繁体   中英

custom alert box in android

The class below is in a file Test.java and I want to call it from the function of public class Test. Now i dont know how to access the function to show the alertdialog . I mean how to access onCreateDialog(Bundle savedInstanceState) of the class below , from another method?

the code below is copied from this source

  class MyCustomDialog extends DialogFragment{
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(inflater.inflate(R.layout.notification_list_layout, null))
        // Add action buttons
               .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // sign in the user ...
                   }
               })
               .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       MyCustomDialog.this.getDialog().cancel();
                   }
               });      
        return builder.create();
    }

}

I want something like this 在此处输入图片说明

MyCustomDialog custDialog = new MyCustomDialog();
custDialog.show(custDialog.getFragmentManager(), "Info"); 

I think this should work MyCustomDialog custDialog = new MyCustomDialog(); custDialog.show(manager, tag) MyCustomDialog custDialog = new MyCustomDialog(); custDialog.show(manager, tag)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM