0

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Nazim ch
  • 834
  • 8
  • 20

1 Answers1

1

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.

CptEric
  • 897
  • 9
  • 23