diff --git a/app/src/main/java/iammert/com/expandablelayout/MainActivity.java b/app/src/main/java/iammert/com/expandablelayout/MainActivity.java index bb846fa..7ae184b 100644 --- a/app/src/main/java/iammert/com/expandablelayout/MainActivity.java +++ b/app/src/main/java/iammert/com/expandablelayout/MainActivity.java @@ -66,6 +66,7 @@ public Section getSection() { section.children.add(fruit3); section.children.add(fruit4); section.children.add(fruit5); + section.expanded = true; return section; } } diff --git a/expandablelib/src/main/java/iammert/com/expandablelib/ExpandableLayout.java b/expandablelib/src/main/java/iammert/com/expandablelib/ExpandableLayout.java index 76f9e2a..d44d0be 100644 --- a/expandablelib/src/main/java/iammert/com/expandablelib/ExpandableLayout.java +++ b/expandablelib/src/main/java/iammert/com/expandablelib/ExpandableLayout.java @@ -114,6 +114,9 @@ public void addChild(P parent, C child) { } if (parentIndex != NO_INDEX) { notifyItemAdded(parentIndex, child); + if (sections.get(parentIndex).expanded) { + expand(parent); + } } } @@ -129,6 +132,9 @@ public void addChildren(P parent, List children) { } if (parentIndex != NO_INDEX) { notifyItemAdded(parentIndex, children); + if (sections.get(parentIndex).expanded) { + expand(parent); + } } } @@ -187,7 +193,7 @@ public void onClick(View view) { addView(sectionLayout); } - public

void expand(@NonNull P parent) { + private

void expand(@NonNull P parent) { for (int i = 0; i < sections.size(); i++) { if (parent.equals(sections.get(i).parent)) { ViewGroup sectionView = ((ViewGroup) getChildAt(i)); @@ -201,7 +207,7 @@ public

void expand(@NonNull P parent) { } } - public

void collapse(@NonNull P parent) { + private

void collapse(@NonNull P parent) { for (int i = 0; i < sections.size(); i++) { if (parent.equals(sections.get(i).parent)) { ViewGroup sectionView = ((ViewGroup) getChildAt(i));