0

I have a RecyclerView that has fixed size and divider decoration. The views in the adapter are ViewSwitchers. I want the ViewSwitcher to go back to its original view when the ViewHolder is recycled so that it shows the correct view when the user scrolls.

When I override OnViewDetatchedFromWindow, and scroll, the RecyclerView now only shows every 5th view and there is a lag in scrolling.

Here is my Adapter Code:

@Override
public void onViewDetachedFromWindow(ViewHolder holder) {
    super.onViewDetachedFromWindow(holder);
    holder.vs.reset(); 
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    ViewSwitcher vs = new ViewSwitcher(parent.getContext());
    vs.addView(LayoutInflater.from(parent.getContext()).inflate(
            R.layout.layout_audio_row, parent, false), 0);
    vs.addView(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_audio_menu_row,
    parent, false), 1);
    vs.setMeasureAllChildren(false);
    Animation showView = AnimationUtils.loadAnimation(parent.getContext(),
            android.R.anim.fade_in);
    vs.setInAnimation(showView);
    //vs.setOutAnimation(hideView);
    ViewHolder vh = new ViewHolder(vs);
    return vh;
}

Am I calling vs.reset() in the appropriate location? Thanks so much in advance!

  • why not in onBindViewHolder? – Selvin Dec 29 '14 at 20:25
  • Thanks for your reply! Unfortunately that did not work. I figured out the problem, and it is with using reset() itself. This method hides all views rather than going back to the 1st view. I can implement a fix now. – user2497757 Dec 29 '14 at 22:11

0 Answers0