2

I have a RecyclerView inside viewPager. When I scroll the view pager the content in Recyclerview is not correct. I tried to call notifyDataSetChanged() in onPageScrolled() and onResume(). but still content is not refreshing when page scrolled.

how to solve this problem? Thanks in advance

viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {       //viewPager.setOffscreenPageLimit(App.getInstance().getFragmentList().size());
        favListAdapter.notifyDataSetChanged();

        }
    @Override
    public void onPageSelected(int position) {   
      //favListAdapter.notifyDataSetChanged();
        }
    @Override
    public void onPageScrollStateChanged(int state) {
    });


@Override
public void onResume(){
    if(favListAdapter!=null){
        favListAdapter.notifyDataSetChanged();

    }
    super.onResume();
}

EDIT:

I am inflating the view like this:

@Override public RecyclerView.ViewHolder {

    onCreateViewHolder(final ViewGroup viewGroup, int viewType) { 

    View v1 = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout‌​.item_add, viewGroup, false); 
    return new CellViewHolder(v1); 

    }
}
ClassA
  • 2,480
  • 1
  • 26
  • 57

1 Answers1

0

I think your problem is that the content(recyclerView) inside viewPager is not getting the dynamic data which should be called when the recyclerview is shown on the screen.

It's because the viewPager loads the page left and right of the current page for soft transition.

So, you should rather call the method which changes the recyclerView's contents on the onPageScrolled of the ViewPager.OnPageChangeListener.

March3April4
  • 2,131
  • 1
  • 18
  • 37