Reputation: 3761
Apart from setOnCheckedChangeListener
, is there any way through which I can check that user has actually touched the screen and checked/unchecked the checkbox
.
I'm asking this question because my flow is going inside the setOnCheckedChangeListener
even if the user has not performed the check.
Upvotes: 1
Views: 117
Reputation: 676
In your setOnCheckedChangeListener()
method you can take a counter and increment it. After that, where you want to use it you compare it with your previous value.
Upvotes: 0
Reputation: 3370
Take one boolean flag. Example: boolean realyCkecked = false;
In setOnCheckedChangeListener:
If(realyCkecked == false) {
realyCkecked = true;
}
Then check that realyCkecked is true / false
If(realyCkecked) {
System.out.println("Checked Atleast Once.");
} else {
System.out.println("Not checked yet.");
}
So, you can know that even any time CheckBox is checked or not.
Upvotes: 1
Reputation: 1975
This way u can have a boolean to see if ur checkbox is checked.
Use this in your java code.
CheckBox cb = findviewById(R.id.checkbox1);
if(cb.isChecked()){
//it is checked
}
//else it is not checked
Upvotes: 1