4
I have a AlertDialog
with a custom layout with 2 checkboxes. But even if I click one of these checkboxes, by clicking the accept or cancel buttons (alert.setPositiveButton
or the alert.setNegativeButton
), I get the default values of checkboxes and I don’t know if I clicked on them or not.
Creation of the Alertdialog
AlertDialog.Builder alert = new AlertDialog.Builder(novo_layout.this);
alert.setCancelable(false);
LayoutInflater inflater = this.getLayoutInflater();
alert.setView(inflater.inflate(R.layout.layout_alert, null));
alert.setMessage(IdAsString);
Variables from the checkboxes
View view = inflater.inflate(R.layout.layout_alert, null);
sentado = (CheckBox)view.findViewById(R.id.sentado);
livre = (CheckBox)view.findViewById(R.id.livre);
Checking of checkboxes
alert.setPositiveButton("X", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(!sentado.isChecked()&&!livre.isChecked()){
Toast.makeText(getApplicationContext(), "Os dados não foram gravados, indroduza uma posição", Toast.LENGTH_SHORT).show();
//checkBoxClicked.setChecked(false);
}
Every time you check if(!sentado.isChecked()&&!livre.isChecked())
returns true (by default, no checkbox is clicked), even if I have clicked on a checkbox.
Look at it this way: if (!seated.isChecked()) && (!free.isChecked()) {
– Reginaldo Rigo