报警功能,显示消息和开始意图



function alerta() by android with params: string, intent, int——string for message, intent可以为null, action可以为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();
}

像这样跟随

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();
}

相关内容

  • 没有找到相关文章