简体   繁体   中英

Why notifyDataSetChanged not working on some devices?

Helo,

I've got a viewpager with 5 fragments.

My problem is, that calling

 viewpager.getAdapter().notifyDataSetChanged();

doesn't work properly on some devices.

For example, on my BQ Aquaris mobile phone it works fine. It refreshes all the five fragments.

But on my Huawei Honor mobile phone it just refresh the first fragment, and the others are left like they are.

How can I avoid this problem?

BQ Aquaris android version is: 7.1.1

Huawei Honor android version is: 7.0

You can try to set viewPager.setOffscreenPageLimit to 5 (see https://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int) for more information).

But it is not recommended to hold a lot of pages in memory. An alternative is to use the viewPager.addOnPageChangeListener and update the corresponding fragment.

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