Search code examples
javaandroidfragmentandroid-viewpager2

ViewPager2 not updating fragment with POSITION_NONE


I have implemented ViewPager2 and implemented with 2 tabs. I want to refresh each fragment between consecutive swipe with the following code but it is not working.

@Override
public int getItemCount() {
    return POSITION_NONE;
}

It throws following crash error:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 5842
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.material.tabs.TabLayout$Tab com.google.android.material.tabs.TabLayout$Tab.setIcon(int)' on a null object reference

Please suggest appropriate way to accomplish this.


Solution

  • Solved, this issue by updating UI from onResume method of fragment life cycle.