I have a checkbox in childview of expandablelistview and set data according to list, now if i selected group from top to bottom then it will work fine but if i select random positions of group then another checkbox in child is selected also if i change the state of checkbox then it will randomly change state of another checkbox
public class FilterExpandableViewAdapter extends BaseExpandableListAdapter {
private Context context;
private HashMap < Integer, Integer > mChildCheckStates = new HashMap < > ();
private List < FacetView > facetViewList = new ArrayList < FacetView > ();
private ArrayList < ArrayList < Boolean >> checkStates = new ArrayList < ArrayList < Boolean >> ();
public FilterExpandableViewAdapter(Context context) {
this.context = context;
}
public void setData(List < FacetView > facetViewList) {
this.facetViewList = facetViewList;
}
@Override
public int getGroupCount() {
return facetViewList == null ? 0 : facetViewList.size();
}
@Override
public int getChildrenCount(int i) {
return facetViewList == null ? 0 : this.facetViewList.get(i).getEntry().size();
}
@Override
public Object getGroup(int i) {
return this.facetViewList.get(i).getName();
}
@Override
public Object getChild(int i, int i1) {
return this.facetViewList.get(i).getEntry().get(i1).getLabel();
}
@Override
public long getGroupId(int i) {
return i;
}
@Override
public long getChildId(int i, int i1) {
return i1;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
@Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
@Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
String listTitle = (String) getGroup(i);
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.filter_parent_list_view, null);
}
TextView tvheading = view.findViewById(R.id.tv_filter_header);
tvheading.setText(listTitle);
ImageView imgViewArrow = view.findViewById(R.id.img_view_arrow_filter);
if (b) {
imgViewArrow.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_arrow_down_grey_25dp));
imgViewArrow.setRotation(180);
} else {
imgViewArrow.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_arrow_down_grey_25dp));
imgViewArrow.setRotation(0);
}
return view;
}
@Override
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
ChildHolder childHolder;
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.filter_child_view, null);
childHolder = new ChildHolder();
childHolder.checkBox = view.findViewById(R.id.cb_filter_child_view);
view.setTag(childHolder);
} else {
childHolder = (ChildHolder) view.getTag();
}
childHolder.checkBox.setText(getChild(i, i1).toString());
childHolder.checkBox.setChecked(checkStates.get(i).get(i1));
String expandedListText = (String) getChild(i, i1);
String hasMultipleSelection = facetViewList.get(i).getExtendedData().getAllowMultipleValueSelection();
childHolder.checkBox = view.findViewById(R.id.cb_filter_child_view);
childHolder.checkBox.setText(expandedListText + " check box");
if (hasMultipleSelection.equalsIgnoreCase("true")) {
}
if (hasMultipleSelection.equalsIgnoreCase("false")) {
try {
childHolder.checkBox.setChecked(i1 == mChildCheckStates.get(i));
} catch (Exception e) {
e.printStackTrace();
}
childHolder.checkBox.setTag(i1);
childHolder.checkBox.setOnClickListener(view1 - > {
mChildCheckStates.put(i, (Integer) view1.getTag());
notifyDataSetChanged();
});
}
return view;
}
class ChildHolder {
CheckBox checkBox;
Boolean state = false;
}
@Override
public boolean isChildSelectable(int i, int i1) {
return true;
}
Aucun commentaire:
Enregistrer un commentaire