I have the following dialogConfirme
method in which it contains a custom dialog declared as public static
to return a value of type boolean
. The static
issue is so I can call any class using a context
as shown below:
static boolean flag = false;
public static boolean dialogConfirme(final Context context, String mensagem) {
final Dialog myDialog = new Dialog(context);
myDialog.setContentView(R.layout.material_dialog_exit);
myDialog.setTitle(mensagem);
Button btnSim = (Button) myDialog.findViewById(R.id.btnOption1);
btnSim.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
flag = true;
myDialog.dismiss();
}
});
Button btnNao = (Button) myDialog.findViewById(R.id.btnOption2);
btnNao.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
flag = false;
myDialog.dismiss();
}
});
myDialog.show();
return flag;
}
Doubt
Having the following condition in another class and would like the value to return the moment I clicked the button:
boolean dialog = dialogConfirme;
if(dialog){
//retornou verdadadeiro ..
} else {
//retornou falso
}
However, before clicking any button inside the dialog method, I already get a return. Would I be able to get the return only the moment I click the btnSim
or btnNao
buttons? As? Would it be a "bad practice" to follow this thought?