I am trying to make a custom dialog with a set of check boxes, and I want to validate them so that if the user clicks the ok button without selecting any one of them, a message will be displayed to the user asking them to select at least one choice. If they have (selected a t least one choice) a message will displayed saying which check boxes that the user has checked.
I can’t continue the validation, can anybody help me and does anybody have any ideas about what I should do to validate the check boxes in a custom dialog?
Button conditions_btn=(Button)findViewById(R.id.conditions_btn);
conditions_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final Dialog ConditionsDialog =new Dialog(ProfileView.this);
ConditionsDialog.setContentView(R.layout.diseases);
ConditionsDialog.setTitle(" select your health condition ");
DCB1=((CheckBox) ConditionsDialog.findViewById(R.id.CB1));
DCB2=((CheckBox) ConditionsDialog.findViewById(R.id.CB2));
DCB3=((CheckBox) ConditionsDialog.findViewById(R.id.CB3));
DCB4=((CheckBox) ConditionsDialog.findViewById(R.id.CB4));
Diseses_ok_btn= ((Button) ConditionsDialog.findViewById(R.id.ok_button));
Diseses_ok_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//validate the check boxes
if( DCB1.isChecked()== false&&DCB2.isChecked()==false&&DCB3.isChecked()==false&&DCB4.isChecked()==false ) {
showMessage(" please select your health condition ");
} else {
// what should i do here to get the check boxes that have been checked ??
}
}
});
Diseses_cancel_btn=((Button)ConditionsDialog..findViewById(R.id.cancel_button));
Diseses_cancel_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ConditionsDialog.dismiss();
}
});
ConditionsDialog.show();
}
});
I am probably misunderstanding your question, but here goes…
I don’t know how to access the names of your diseases, but I would do something similar this in your ‘validation block’: