On Android, I need a checkbox (or checkbox-like component) which can represent/control a flag for a number of selected items. There are 3 possibilities which I need to represent:
I'm imagining something like this:
If the user selects the checkbox when it's in state 3, it will switch to state 1. Thereafter, it will only toggle between states 1 & 2.
If you're familiar with the checkboxes in the attributes section of the file properties dialog in Windows, that's what I'm after.
Is there a native Android UI widget, or an existing open-source widget, which can do this?
I'm fairly confident I could do my own implementation, but I'd rather not re-invent the wheel!
You can call isChecked() on a checkbox to get its status.
By default, the android CheckBox will be in the OFF (Unchecked) state. We can change the default state of CheckBox by using android:checked attribute. In case, if we want to change the state of CheckBox to ON (Checked), then we need to set android:checked = “true” in our XML layout file.
Just add the android:clickable="false" attribute in the layout xml.
So, the method to know if the check box is checked is : (CheckBox) yourCheckBox. isChecked() it returns true if the check box is checked.
I think you'd be best of with your own implementation. And it will be a fairly simple one, just use the: setOnCheckedChangeListener, here is a simple tutorial that just shows the use of this listeners, you will just implement changing your flags, and setting some of your checkboxes checkable when in the correct state.
http://developer.android.com/guide/topics/ui/controls/checkbox.html
hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With