简体   繁体   中英

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.

通过从片段生命周期的 onResume 方法更新 UI 解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM