I have a checkbox in a custom dialog I've created. The onClick function seems to work fine but the box reverts to unchecked if I close the dialog and re-open. I'm assuming something is getting refreshed and not remembering the state of the checkbox. How do I get it to preserve the check?
Here's my dialog:
public Dialog onCreateDialog() {
AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.popuplayout, null);
helpBuilder.setView(layout);
helpBuilder.setPositiveButton(
"OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Close the dialog
}
});
AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
return helpBuilder.create();
}
Checkbox method:
public void onCheckboxClicked(View view){
boolean checked = ((CheckBox) view).isChecked();
switch(view.getId()) {
case R.id.check_devices:
if(checked)
abc();
break;
}
}