Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partially selected checkbox on Android?

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:

  1. Flag is set for all items.
  2. Flag is set for none of the items.
  3. Flag is set for some of the items.

I'm imagining something like this:

enter image description here

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!

like image 230
vaughandroid Avatar asked Dec 14 '12 11:12

vaughandroid


People also ask

How can I check CheckBox in android?

You can call isChecked() on a checkbox to get its status.

How do I toggle CheckBox in android?

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.

How do I stop a CheckBox from being unchecked android?

Just add the android:clickable="false" attribute in the layout xml.

How do I know if my CheckBox is clicked android?

So, the method to know if the check box is checked is : (CheckBox) yourCheckBox. isChecked() it returns true if the check box is checked.


1 Answers

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!

like image 140
JanBo Avatar answered Oct 20 '22 03:10

JanBo