0

I am generating a list of check boxes, after parsing it from a JSON. When the submit button is pressed i want to know which all boxes are checked. How do i do this ?

My xml code (Omitting very obvious stuff like height, width, xmlns etc.) :

<LinearLayout>
    <TextView
        android:id="@+id/title"
        android:text="@string/CatalogueTitle" />
    <CheckBox
        android:id="@+id/checkBox" />
</LinearLayout>

This java snippet populates data and adds the text to the adjacent TextView

TextView title = (TextView) v.findViewById(R.id.title);
CheckBox cbox = (CheckBox) v.findViewById(R.id.checkBox);
if (title != null) {
    title.setText(tdunit.title);
}

Onsubmit, how can I identify a checkbox?

Jaseem
  • 2,236
  • 6
  • 28
  • 35

1 Answers1

1

So Onclick of Submit button u can do this,From this you will get the items of checked boxes,in that way u will know which boxes are checked:-

@Override
public void onClick(View v) 
{
        System.out.println("check"+getListView().getCheckItemIds().length);

        for (int i = 0; i < getListView().getCheckItemIds().length; i++)
        {
            System.out.println(getListView().getAdapter().getItem((int)getListView().getCheckItemIds()[i]).toString());                 
        }   

}
stella
  • 441
  • 4
  • 12