I'm trying to display expandableListView
in android alertDialog
everything is working fine. I'm able to check/un-check the checkbox
that I'm showing in childView
But I have to do some stuff when I check/un-check the checkbox, Here its not working.
When I implement checkbox check listener in adapter
class it works perfect, I need it in the class from where I'm setting adapter
. I searched over the internet and tried many ways, Now when I make the child click listener to false
inside adapter like
itemView.setClickable(false);
The click listener in the origin class is working. But on expand/collapse the expandableListView
my checkbox get unselected.
Here is what I have When I size to expand its child the child of color get un-selected
Here is my code in origin class called ProductsFragment the relevant code
ExpandableListView myList = new ExpandableListView(context);
ExpandableListAdapter myAdapter = new ExpandableListAdapter(
headerList, hashMap, true);
myList.setAdapter(myAdapter);
myList.setGroupIndicator(null);
builder.setView(myList);
myList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(final ExpandableListView parent, View v,
final int groupPosition, final int childPosition, long id) {
MenuSubCategory subCategory = (MenuSubCategory) parent.getExpandableListAdapter()
.getChild(groupPosition, childPosition);
CheckBox checkBox = (CheckBox) v;
checkBox.toggle();
utils.printLog("IsChecked = " + ((CheckBox) v).isChecked());
if (((CheckBox) v).isChecked()) {
utils.printLog("SubCatListItemId = " + subCategory.getMenuSubCategoryId());
selectedFilters.add(subCategory.getMenuSubCategoryId());
} else {
String filterId = subCategory.getMenuSubCategoryId();
if (!filterId.isEmpty())
selectedFilters.remove(filterId);
}
return true;
}
});
I did not get the difference between return true/ return false in expandableListView
s child click listener. I tried both way.
Please tell me the best way to implement expandableListView
with chechbox
in it. In a way that will make it work checkbox check/un-check and retain the check state on expand/collapse.
All effort would be appreciated. Thanks in advance.
Additional: for the statement
I'm able to check/un-check the checkbox
that means only selection/un-selection animation happens not the event, and its the case when I do not write itemView.setClickable(false);
in adapter class
Aucun commentaire:
Enregistrer un commentaire