What is the difference between true and false in this code?
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
int cbcheck = 1;
} else {
int cbcheck = 0;
}
}
@Override
public void onClick(View v) {
;
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.registerbut:
onCheckedChanged(cbagree, false);
if (cbcheck == 1) {
Intent intent = new Intent(this,
RegisterScreen2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
} else if (cbcheck == 0){
}
break;
}
}
The part where it says onCheckedChanged(cbagree, true); what would happen if I passed false instead?
I wish to make it so if the box is checked the intent will run, otherwise it’ll state for you to check the box. I have tried saving the checkboxing and then loading it using savepreferences and loadpreferences but I find that is too much hassle. Is there any other way to accomplish this?
This is in android btw.
As it’s written, there’s no difference since your function
onCheckedChanged()literally does nothing: In two local blocks local variables get declared which immediately go out of scope, and there is no net effect of this function at all.Perhaps you mean to modify some private class member instead?
Suggestion: here’s an idea on passing the state change through a private member: