I am able to get selected check box value in Expandable view. Now I want to auto selected these check box again if their value exists in array.
I am getting clicked checkbox value as pair(groipId, childId). So when user click edit, I want these check box auto select. All of my data coming from some API.
This is the code for getting select box value.
final CheckBox cb = (CheckBox) convertView.findViewById(R.id.childCkBox);
// add tag to remember groupId/childId
final Pair<Long, Long> tag = new Pair<Long, Long>(
getGroupId(groupPosition),
getChildId(groupPosition, childPosition));
cb.setTag(tag);
// set checked if groupId/childId in checked items
cb.setChecked(mCheckedItems.contains(tag));
// set OnClickListener to handle checked switches
cb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final CheckBox cb = (CheckBox) v;
final Pair<Long, Long> tag = (Pair<Long, Long>) v.getTag();
if (cb.isChecked()) {
mCheckedItems.add(tag);
} else {
mCheckedItems.remove(tag);
}
}
});
txtListChild.setText(childText);
public Set<Pair<Long, Long>> getCheckedItems() {
return mCheckedItems;
}
Editing and suggesting are welcome.
Aucun commentaire:
Enregistrer un commentaire