Skip to content

Commit 5a7b1ed

Browse files
committed
- Fix initial expand.
1 parent a5b2f05 commit 5a7b1ed

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

app/src/main/java/iammert/com/expandablelayout/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public Section<FruitCategory, Fruit> getSection() {
6666
section.children.add(fruit3);
6767
section.children.add(fruit4);
6868
section.children.add(fruit5);
69+
section.expanded = true;
6970
return section;
7071
}
7172
}

expandablelib/src/main/java/iammert/com/expandablelib/ExpandableLayout.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public <P, C> void addChild(P parent, C child) {
114114
}
115115
if (parentIndex != NO_INDEX) {
116116
notifyItemAdded(parentIndex, child);
117+
if (sections.get(parentIndex).expanded) {
118+
expand(parent);
119+
}
117120
}
118121
}
119122

@@ -129,6 +132,9 @@ public <P, C> void addChildren(P parent, List<C> children) {
129132
}
130133
if (parentIndex != NO_INDEX) {
131134
notifyItemAdded(parentIndex, children);
135+
if (sections.get(parentIndex).expanded) {
136+
expand(parent);
137+
}
132138
}
133139
}
134140

@@ -187,7 +193,7 @@ public void onClick(View view) {
187193
addView(sectionLayout);
188194
}
189195

190-
public <P> void expand(@NonNull P parent) {
196+
private <P> void expand(@NonNull P parent) {
191197
for (int i = 0; i < sections.size(); i++) {
192198
if (parent.equals(sections.get(i).parent)) {
193199
ViewGroup sectionView = ((ViewGroup) getChildAt(i));
@@ -201,7 +207,7 @@ public <P> void expand(@NonNull P parent) {
201207
}
202208
}
203209

204-
public <P> void collapse(@NonNull P parent) {
210+
private <P> void collapse(@NonNull P parent) {
205211
for (int i = 0; i < sections.size(); i++) {
206212
if (parent.equals(sections.get(i).parent)) {
207213
ViewGroup sectionView = ((ViewGroup) getChildAt(i));

0 commit comments

Comments
 (0)