Reputation: 2285
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?
Upvotes: 0
Views: 767
Reputation: 441
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());
}
}
Upvotes: 1