Android recyclerview, databinding and sub view animation
<p>Could you help me to find a proper way without leak to animate a RecylcerView's item's sub item?</p>

<p>I want to create a two level drawer menu, where the menu items are in a RecyclerView created by an adapter. Some of the menu items contain sub items, and this items can open with an arrow at the end to add sub items to the list below the parent item.
I want to animate those arrows to rotate 180 degree when the adapter detects parent item have to open/close and show/remove sub items.</p>

<p>The whole thing is working but I'm not happy with the solution of the animation. :(</p>

<p>What the tricky part is that I'm using databinding to fill those item's with data. </p>

<p>Here's my class what contains the data:</p>

<pre><code>public class MenuItem extends BaseObservable {

    public ObservableField&lt;String&gt; name = new ObservableField&lt;&gt;();
    public ObservableBoolean selected = new ObservableBoolean(false);
    public ObservableBoolean isSubItem = new ObservableBoolean(false);
    public MenuItem parent;
    public List&lt;MenuItem&gt; subItems = new ArrayList&lt;&gt;(0);
    private DrawerAdapter.OnDrawerItemClickListener listener;
    /* It's a potencial leak */
    public View arrow;

    .....
    public void animateArrow(boolean isOpen) {
        if(arrow == null)
           return;

        float degrees = isOpen ? 180f : 0f;
        arrow.animate().roatate(degrees).setDuration(300).start();
    }

}
</code></pre>

<p>Here's my ViewHolder:</p>

<pre><code>public class DrawerItemHolder extends RecyclerView.ViewHolder {

    public DrawerItemBinder ui;

    public DrawerItemHolder(View itemView) {
        super(itemView);
        ui = DataBindingUtil.bind(itemView);
    }
}
</code></pre>

<p>Here's how I bind to ViewHolder:</p>

<pre><code>@Override
public void onBindViewHolder(DrawerItemHolder holder, int position) {
    MenuItem item = items.get(position);
    if(!item.subItems.isEmpty())
        item.arrow = holder.ui.arrow;
    holder.ui.setData(item);
}
</code></pre>

<p>I attach the arrow view only those items what has sub item. </p>

<p>And when the adapter decides to open an item it calls this method:</p>

<pre><code>private void openCategories(MenuItem item) {
    ...

    /* Animate to close state the already opened category's arrow */
    if(openedCategory != null)
        openedCategory.animateOpener(false);

    openedCategory = item;
     /* Animate to opened state the newly opened category */
    openedCategory.animateOpener(true);

    notifyItemRangeInserted(...);
}
</code></pre>

<p>The openedCategory is also a MenuItem, a reference to the parent item what is actually open.</p>

<p>And when it want to close an item calls this:</p>

<pre><code>private void closeCategories() {
    if (openedCategory == null)
        return;

   ...
    notifyItemRangeRemoved(...);

     /* Animate to closed state the already opened category's arrow */
    openedCategory.animateOpener(false);
    openedCategory = null;
}
</code></pre>

<p>So my problem is this. How can I animate a subview of parent items without leaking those arrow views by holding reference about them in the MenuItem class?</p>

<p>Best Regards!</p>