1
I have the following method to create a Dialog
in an Android app:
public static void alertBuilder(String mensagem, Type tipo, Context contexto){
Dialog dialog = new Dialog(contexto, R.style.alert);
dialog.setContentView(R.layout.alert_box);
TextView text = dialog.getWindow().findViewById(R.id.mensagem);
TextView type = dialog.getWindow().findViewById(R.id.alerta);
ImageView image = dialog.getWindow().findViewById(R.id.imagem);
switch (tipo) {
case SUCCESS:
image.setImageDrawable(Drawable.createFromPath("@drawable/ic_ok"));
type.setText("Pronto!");
text.setText(mensagem);
break;
case ERROR:
type.setText("Atenção!");
text.setText(mensagem);
break;
}
dialog.show();
}
And I wanted to add a "ok" button that would close the Dialog
when it was clicked, but there is no method of setPositiveButton
in class Dialog
as in class AlertDialog
.
I can’t make the conversion from one class to another, because as you see there in this piece of code, I have a layout
universal to the Dialog
of my application, which modifies the message of layout
depending on the type of event.
Any hints on how to add this button?