In my android app I have fragments & in one of fragment I have checkbox. This checkbox has listener like this, that shows alert dialog on check:
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked) {
alertDialog.setPositiveButton(R.string.is_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
NItem item = new NItem();
item.isOk = 1;
setItem(item);
}
});
alertDialog.setNegativeButton(R.string.is_not_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
NItem item = new NItem();
item.isOk = 0;
setItem(item);
}
});
alertDialog.show();
}
}
When I check checkbox & go to other fragment & go back to fragment where this checkbox, the method onCheckedChanged is called again. I think it is because fragment restored from saved state. How to prevent this?