0

I am trying to implement animation in my RecyclerView as mentioned here

I have confusion to use this code as mentioned in post.

@Override
    public void onViewDetachedFromWindow(final RecyclerView.ViewHolder holder)
    {
        ((CustomViewHolder)holder).clearAnimation();
    }

Its giving me error like this and I am not able to solve it

enter image description here

I have also confusion in add

public void clearAnimation()
    {
        mRootLayout.clearAnimation();
    }

How should I add and use it ?

Thanks

Priya
  • 1,602
  • 4
  • 22
  • 37
  • Use your ViewHolder instead of Parent class `RecyclerView.ViewHolder`. That is, pass the name of the class type that you defined in your project that extends `RecyclerView.ViewHolder` as argument to the function `onViewDetached....()` – Gotiasits Sep 25 '17 at 15:52

2 Answers2

0

How about making your task easier and use a library already having that features?
I personally recommend try to give a look at those library`s : 1. https://github.com/cymcsg/UltimateRecyclerView 2. https://android-arsenal.com/details/1/5797 3. https://github.com/h6ah4i/android-advancedrecyclerview

Im using those librarys and work as expected.

Update : As you don`t provide more code to understand your exact situation i just can provide tips: Try to cancel your animation on onViewDetachedFromWindow.

try to reverse animation on the same method :

    @Override
 public void onViewDetachedFromWindow(ViewHolder holder) {
if (holder.getItemViewType() == poition) ((ItemView) 
  holder.itemView).reverseAllAnimations();
 }
Sz-Nika Janos
  • 811
  • 6
  • 19
0

Explanation:

Since method onViewDetachedFromWindow()expects as argument type a class which extends RecyclerView.ViewHolder, Java will not let you override that function using a parent class.

Solution:

You need to use the same type as an argument as generic type you passed to your adapter. For example if your adapter class is defined as:

private class NewQouteAdapter extends RecyclerView.Adapter<NewQouteAdapter.ViewHolder>{ ...  }

You can use as type either NewQouteAdapter.ViewHolder or just ViewHolder to onViewDetachedFromWindow() function argument.

As for the second part, in the example you linked clearAnimation() is defined in ViewHolder class, and use View function on holder instance, wich is available through itemView variable, then called in AdapterClass on instance of holder object.

Or do not use your own clearAnimation() and just call View method in your adapter: holder.itemView.clearAnimation();

Gotiasits
  • 1,135
  • 1
  • 10
  • 21