0

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.

Bishwash
  • 854
  • 1
  • 9
  • 22
  • Can you try by checking when the fragment becomes visible(`setUserVisibleHint`) and then refresh the fragment , also do you want to refresh each fragment when we swipe? – aryanknp Sep 05 '20 at 12:22

1 Answers1

0

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

Bishwash
  • 854
  • 1
  • 9
  • 22