1
I would like the open Dialog to be closed when I click on the return button of the mobile phone. I know that to close a dialog we use the Dismiss, but I don’t know how we declare the back button of the cell phone.
public class DialogValor {
Button butNum1, butNum2, butNum3, butNum4, butNum5, butNum6, butNum7, butNum8, butNum9, butVirgula, butNum0, butOk;
TextView txtValorADD;
ImageButton imbClear;
public interface FinalizarDialogo
{
void ResultadoDialogo (String txtValorADD);
}
private FinalizarDialogo interfaz;
public DialogValor(final Context context, FinalizarDialogo actividad) {
interfaz = actividad;
final Dialog dialogo = new Dialog(context);
dialogo.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogo.setCancelable(false);
dialogo.setContentView(R.layout.alerta);
txtValorADD = (TextView) dialogo.findViewById(R.id.txtValorADD);
imbClear = (ImageButton) dialogo.findViewById(R.id.imbClear);
butNum0 = (Button) dialogo.findViewById(R.id.butNum0);
butNum1 = (Button) dialogo.findViewById(R.id.butNum1);
butNum2 = (Button) dialogo.findViewById(R.id.butNum2);
butNum3 = (Button) dialogo.findViewById(R.id.butNum3);
butNum4 = (Button) dialogo.findViewById(R.id.butNum4);
butNum5 = (Button) dialogo.findViewById(R.id.butNum5);
butNum6 = (Button) dialogo.findViewById(R.id.butNum6);
butNum7 = (Button) dialogo.findViewById(R.id.butNum7);
butNum8 = (Button) dialogo.findViewById(R.id.butNum8);
butNum9 = (Button) dialogo.findViewById(R.id.butNum9);
butVirgula = (Button) dialogo.findViewById(R.id.butVirgula);
butOk = (Button) dialogo.findViewById(R.id.butOk);
butNum0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("0");
}
});
butNum1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("1");
}
});
butNum2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("2");
}
});
butNum3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("3");
}
});
butNum4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("4");
}
});
butNum5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("5");
}
});
butNum6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("6");
}
});
butNum7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("7");
}
});
butNum8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("8");
}
});
butNum9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append("9");
}
});
butVirgula.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtValorADD.append(",");
}
});
imbClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(txtValorADD.getText().length()==0)
{
}
else {
txtValorADD.setText(txtValorADD.getText().subSequence(0, txtValorADD.getText().length() - 1));
}
}
});
butOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (txtValorADD.getText().length()==0)
{
dialogo.dismiss();
}
else{
interfaz.ResultadoDialogo(txtValorADD.getText().toString());
dialogo.dismiss();}
}
});
dialogo.show();
}
}
Post the code of your
dialog
.– StatelessDev
already friend, I edited.
– Romão Gomes