You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-3Lines changed: 30 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,13 +55,13 @@ Groups are the building block of Groupie. An individual `Item` (the unit which
55
55
56
56
Kotlin
57
57
```kotlin
58
-
groupAdapter+=HeaderItem()
59
-
groupAdapter+=CommentItem()
58
+
groupAdapter.add(HeaderItem())
59
+
groupAdapter.add(CommentItem())
60
60
61
61
val section =Section()
62
62
section.setHeader(HeaderItem())
63
63
section.addAll(bodyItems)
64
-
groupAdapter+=section
64
+
groupAdapter.add(section)
65
65
```
66
66
67
67
Java
@@ -168,6 +168,33 @@ Finally, in your `Item<MyExistingViewHolder>`, override
168
168
}
169
169
```
170
170
171
+
### Add and remove items with `+=` and `-=` in Kotlin
172
+
173
+
`groupie-ktx` provides Kotlin Extensions overriding the `plusAssign` and `minusAssign` operations on both group adapters and sections. This enables a cleaner syntax when creating and modifying layouts.
Instances of `.add()`, `.addAll()`, and `.remove()` can be replaced with `+=` and `-=`
181
+
182
+
```kotlin
183
+
// Without groupie-ktx
184
+
mySection.add(HeaderItem())
185
+
mySection.remove(CommentItem())
186
+
groupAdapter.add(mySection)
187
+
groupAdapter.remove(DescriptionItem())
188
+
189
+
// With groupie-ktx
190
+
mySection +=HeaderItem()
191
+
mySection -=CommentItem()
192
+
groupAdapter += mySection
193
+
groupAdapter -=DescriptionItem()
194
+
```
195
+
196
+
Note: `groupie-ktx` is included with the deprecated `groupie-kotlin-android-extensions`. If you depend on `groupie-kotlin-android-extensions`, you do not need to also depend on this module.
197
+
171
198
### Note:
172
199
173
200
Items can also declare their own column span and whether they are draggable or swipeable.
0 commit comments