mercredi 11 novembre 2015

android get selected checkboxes in a group

im implementing something like a category, so a produt can be in 1 or more categories

now i set a Tag for the CheckBox like

  <CheckBox
                android:id="@+id/c1"
                android:tag="checkbox1"
                android:text="Constituição Estadual"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

and go on

when the user press to save i check if each checkbox is selected than add the tag to a arraylist and convert it to String separed by comma and save

when i need to get the list and set the selected checkbox, i receive the String from db, split into into a String[], iterate over it, find the element in android using the getResource, and then set it to select=true

i see that like a huge job, i saw sometime ago(cant remember) a kind of group of checkbox you just use groupOfCheckBox.getSelected();

if you selected the number one and number 2 it return 1,2..

and to set it checked was easy as groupofCheckBox.setSelect("1,2")

but i cant find it anymore, someone know if i was dreaming about it or really exist some way to do that




Aucun commentaire:

Enregistrer un commentaire