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
New in `SmartRecyclerAdapter` v2.0.0 is support for nested recycler adapter.
33
45
Now you can easily build complex nested adapters without hustle and have full control of the adapter in your view controlling `Fragment` or `Activity`.
Just extend your ViewHolder class with SmartViewHolder and pass in the target type ex `SmartViewHolder<Mail>`.
97
-
Note that the constructor must take `ViewGroup` as parameter, in this case `PosterViewHolder(ViewGroup parentView)`.
101
+
Note that the constructor can both take `View` or `ViewGroup` as parameter, in this case `PosterViewHolder(ViewGroup parentView)` to avoid casting to ViewGroup while inflating.
98
102
The `parentView` is the recyclerView.<br/>
103
+
The method `unbind` has an default implementation and is optional.
99
104
##### Works with Android DataBinding! Just add the DataBinding LayoutInflater in `super` call. 🚀
100
105
101
106
```java
@@ -111,10 +116,15 @@ public class PosterViewHolder extends SmartViewHolder<MoviePosterModel> {
111
116
.load(model.icon)
112
117
.into(imageView);
113
118
}
119
+
120
+
@Override
121
+
publicvoidunbind() {
122
+
Glide.with(imageView).clear(imageView);
123
+
}
114
124
}
115
125
```
116
126
117
-
### View event listener
127
+
### View event listener
118
128
119
129
You can easily assign events to views and add an `ViewEventListener` to the SmartRecyclerAdapter for easy handling.<br/>
120
130
You must extend your `ViewHolder` with `SmartEventViewHolder`.
@@ -135,10 +145,10 @@ Your `ViewHolder` must extend `SmartEventViewHolder`.
Sometimes a ViewHolder created by the Adapter cannot be recycled due to its transient state.
197
+
In order to fix this is to implement `Re` in your `SmartViewHolder` extension so that upon receiving this callback,
198
+
Adapter can clear the animation(s) that effect the View's transient state and return <code>true</code> so that the View can be recycled.
199
+
200
+
```java
201
+
classMovieViewHolder
202
+
extendsSmartViewHolder
203
+
implementsRecyclableViewHolder {
204
+
@Override
205
+
publicbooleanonFailedToRecycleView() {
206
+
// Clear animations or other stuff
207
+
returntrue;
208
+
}
209
+
}
210
+
```
211
+
212
+
### OnViewAttachedToWindowListener and OnViewDetachedFromWindowListener
213
+
214
+
If you want to catch when the view is attached and detached from the window in your ViewHolder you can implement `OnViewAttachedToWindowListener` and `OnViewDetachedFromWindowListener` in your `SmartViewHolder` extension.
215
+
Becoming detached from the window is not necessarily a permanent condition the consumer of an Adapter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.
0 commit comments