2022年7月23日

Android Yes_No Dialog API


import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class Yese_NO_dialog {

   private AlertDialog.Builder builder;;
   private  AlertDialog alertDialog;

   public  interface  Action_event{

       public  void ok_event();
       public  void cancel_event();
       public  void dismiss_event();

   }
   public  Action_event action_event=null;

    public Yese_NO_dialog(Context context){
        builder=new AlertDialog.Builder(context);
    }

    public  void set_message(String message){

        builder.setMessage(message);
    }

    public  void set_cancelable(boolean b){

        builder.setCancelable(b);
    }

    public  void set_ok_btn(String str){

        builder.setPositiveButton(str, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if(action_event!=null)
                    action_event.ok_event();

            }
        });
    }
    public  void set_cancel_btn(String str){
         builder.setNegativeButton(str, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if(action_event!=null)
                    action_event.cancel_event();

            }
        });

    }
    public  void set_title(String title){

        builder.setTitle(title);
    }

    public  void create(){

        alertDialog=builder.create();
        alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {

            if(action_event!=null)
                action_event.dismiss_event();
            }
        });
    }

    public  void show(){

        alertDialog.show();
    }


}





沒有留言:

張貼留言