Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b49e4d63 authored by Georg Hofmann's avatar Georg Hofmann
Browse files

Fixed group and child view caching in SimpleExpandableListAdapter.



Now the adapter reports the correct type count and type for group and child
views by overriding the respective methods from the base class. Each group
view has two types, one for expanded views, one for collapsed views. Each
child view has two types, one for the last view within a group, one for the
other views within a group.

Change-Id: I117b2c0f7e98fb7fe2fdd35c15f7d1f9dc06674f
Signed-off-by: default avatarGeorg Hofmann <georg.hofmann@gmail.com>
parent 42c6d163
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import java.util.Map;
 */
public class SimpleExpandableListAdapter extends BaseExpandableListAdapter {
    private List<? extends Map<String, ?>> mGroupData;
    // Keeps track of if a group is currently expanded or not
    private boolean[] mIsGroupExpanded;
    private int mExpandedGroupLayout;
    private int mCollapsedGroupLayout;
    private String[] mGroupFrom;
@@ -196,6 +198,8 @@ public class SimpleExpandableListAdapter extends BaseExpandableListAdapter {
            int childLayout, int lastChildLayout, String[] childFrom,
            int[] childTo) {
        mGroupData = groupData;
        // Initially all groups are not expanded
        mIsGroupExpanded = new boolean[groupData.size()];
        mExpandedGroupLayout = expandedGroupLayout;
        mCollapsedGroupLayout = collapsedGroupLayout;
        mGroupFrom = groupFrom;
@@ -298,4 +302,52 @@ public class SimpleExpandableListAdapter extends BaseExpandableListAdapter {
        return true;
    }

    /**
     * {@inheritDoc}
     * @return 1 for the last child in a group, 0 for the other children.
     */
    @Override
    public int getChildType(int groupPosition, int childPosition) {
        final int childrenInGroup = getChildrenCount(groupPosition);
        return childPosition == childrenInGroup - 1 ? 1 : 0;
    }

    /**
     * {@inheritDoc}
     * @return 2, one type for the last child in a group, one for the other children.
     */
    @Override
    public int getChildTypeCount() {
        return 2;
    }

    /**
     * {@inheritDoc}
     * @return 1 for an expanded group view, 0 for a collapsed one.
     */
    @Override
    public int getGroupType(int groupPosition) {
        return mIsGroupExpanded[groupPosition] ? 1 : 0;
    }

    /**
     * {@inheritDoc}
     * @return 2, one for a collapsed group view, one for an expanded one.
     */
    @Override
    public int getGroupTypeCount() {
        return 2;
    }

    /** {@inheritDoc} */
    @Override
    public void onGroupCollapsed(int groupPosition) {
        mIsGroupExpanded[groupPosition] = false;
    }

    /** {@inheritDoc} */
    @Override
    public void onGroupExpanded(int groupPosition) {
        mIsGroupExpanded[groupPosition] = true;
    }
}