显示消息和启动意图的警报功能

问题描述 投票:0回答:1

function alerta() by android with params: string, intent, int --- 消息字符串,intent 可以为 null,accion 可以为 1 以启动 intent。显示警报消息的功能。

public void alerta(String mensaje,Intent intent,int accion){ 
AlertDialog alertDialog = new 
AlertDialog.Builder(registro.this).create();
    alertDialog.setTitle("Alerta");
    alertDialog.setMessage(mensaje);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new 
    DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) 
        {
            dialog.dismiss();
            switch(accion){
                case 1:
                    startActivity(intent);
                    break;
                default:
            }
        }
    });
    alertDialog.show();
}
android function alert
1个回答
0
投票

像这样关注

public void showAlert(String mensaje, Intent intent, int accion) {
    // If it's activity mean AlertDialog.Builder(this) or It's fragment AlertDialog.Builder(requireActivity());
    AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
    builder.setTitle("Alerta");
    builder.setMessage(mensaje);
   AlertDialog mDialog = builder.create();
   mDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new
            DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (accion == 1) {
                        startActivity(intent);
                    }
                    dialog.dismiss();
                }
            });
    mDialog.show();
}
© www.soinside.com 2019 - 2024. All rights reserved.