I have the following method to create a Dialog
in an Android application:
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 an "ok" button that closed Dialog
when clicked, but there is no method of setPositiveButton
in class Dialog
as in class AlertDialog
.
I can not do the conversion from one class to another, because as you can see in that code snippet, I have a layout
universal for Dialog
of my application, which modifies the layout
message depending on kind of event.
Any suggestions on how to add this button?