Reputation: 854
I am doing a Lottie animation in Android RecyclerView, but the animation is playing only on a single item and always it is the last item. The onclick is on the correct item, but view of animation is on constant item.
my adapter portion
listingRecyclerItemBinding.quickviewfilled.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quickViewNew("OFF", mValues.get(position).getPropertyIndex(),
mValues.get(position).getDeveloperId(), mValues.get(position).getPublic());
mValues.get(position).setQuickAccess("0");
notifyDataSetChanged();
}
});
listingRecyclerItemBinding.quickviews.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listingRecyclerItemBinding.quickviews.setVisibility(View.GONE);
listingRecyclerItemBinding.addToquick.setVisibility(View.VISIBLE);
listingRecyclerItemBinding.addToquick.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
listingRecyclerItemBinding.addToquick.setVisibility(View.GONE);
quickViewNew("ON", mValues.get(position).getPropertyIndex(),
mValues.get(position).getDeveloperId(),
mValues.get(position).getPublic());
mValues.get(position).setQuickAccess("1");
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
listingRecyclerItemBinding.addToquick.playAnimation();
}
});
How can I deal with the Lottie animation in android recycler view?
Upvotes: 0
Views: 1748
Reputation: 907
If the last element is the only one working, and the other interactions behave correctly, the most probable cause is your code reassigning/recycling your lottie animation alongside the RV until it reaches the last RV element, and being the last one to reassing/reuse, it's the one works.
Upvotes: 1