Search code examples
androidandroid-recyclerviewandroid-viewpager

Updated items on recyclerView are lost when view pager is used


When i change recyclerView data of one tab,data is being reflected(working fine), but when i switch to other tabs and go back to updated tab , the updated items on recyclerView are lost .how to notify viewpager adapter that i have changed data in recyclerAdapter.

enter image description here


Solution

  • Actually, ViewPager loads the next and previous (if any) fragment on initialization and if you will go to the second tab it will load 3rd automatically. You need to use:

    viewpager.setOffscreenPageLimit(3);//3 is the limit not refreshing the fragment till 2 swipes
    

    Hope this will solve your problem.