There are two different item type in my recyclerview adapter. First one is ProductViewHolder and the other one is ShimmerViewHolder.
I have to use shimmer layout in recyclerview items.
I'm using startShimmer() function in ShimmerViewHolder. When recyclerview itemViewType changed as ShimmerViewHolder instead of ProductViewHolder, shimmer alpha animation still continue and make blinking on the ProductViewHolder items. How can i fix this problem ?
Here is the code snippets:
ShimmerViewHolder.kt
class ShimmerViewHolder(
view: View) : RecyclerView.ViewHolder(view) {
private val shimmerLayout: ShimmerFrameLayout = view.findViewById(R.id.shimmerLayout)
fun bind(shimmer: Shimmer?) {
shimmerLayout.setShimmer(shimmer)
shimmerLayout.startShimmer()
}
}
ProductViewHolder.kt:
class ProductViewHolder(
view: View) : RecyclerView.ViewHolder(view) {
private val tvProduct : TextView = view.findViewById(R.id.tvProduct)
fun bind(product: Product) {
tvProduct.text = product.name
}
}
Finally My ProductsAdapter.kt:
class ProductsAdapter(
val products: List<Product>
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val shimmer = Shimmer
.AlphaHighlightBuilder()
.build()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
VIEW_TYPE_PRODUCT -> {
ProductViewHolder(
LayoutInflater.from(context).inflate(R.layout.item_product, parent, false),
)
}
VIEW_TYPE_SHIMMER -> {
ShimmerViewHolder(
LayoutInflater.from(context).inflate(R.layout.item_shimmer, parent, false)
)
}
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is ShimmerViewHolder -> {
holder.bind(shimmer)
}
is ProductViewHolder -> {
holder.bind(product)
}
}
}
}
There are two different item type in my recyclerview adapter. First one is ProductViewHolder and the other one is ShimmerViewHolder.
I have to use shimmer layout in recyclerview items. I'm using startShimmer() function in ShimmerViewHolder. When recyclerview itemViewType changed as ShimmerViewHolder instead of ProductViewHolder, shimmer alpha animation still continue and make blinking on the ProductViewHolder items. How can i fix this problem ?
Here is the code snippets: