Search code examples
androidandroid-viewpagerreloadfragmentpageradapter

Android : Reload particular fragment of fragmentPageAdapter not all?


I am using fragmentpageadapter for pager and i wan to reload the particular fragment with new set of values. NotifyDataSetcanged is reloading all fragments and i am using this line of code as well

 public int getItemPosition(Object object) {
       return POSITION_NONE;
    }

Solution

  • I was having the same problem. All my fragments were being refreshed and being forced to call onCreate() which was messing up my data.

    The getItemPosition() method seemed to be called for each fragment in the adapter. I found if I set an IF statement to catch the fragment that I didn't want refreshed and I returned POSITION_UNCHANGED it would not refresh that fragment

    Using this method you should be able to refresh only the fragment(s) you want to.

    if (object.getClass().getName().equals(NonUpdatingFragment.class.getName()))
    {
        return POSITION_UNCHANGED;
    }
    else
    {
        return POSITION_NONE;
    }