Fragment view in ViewPager is not restored when resuming

前端 未结 6 1433
独厮守ぢ
独厮守ぢ 2020-11-30 12:23

I have ActionBar Tabs setup. It consists of 4 tabs. Everything is fine until I navigate away from TabbedFragment and returning back.

I create tabs like

6条回答
  •  猫巷女王i
    2020-11-30 12:43

    The problem exists in the Fragments you use as tabs, I think. They seem to not show anything when they are resumed (see Fragment lifecycle). The "weird" issue that only the currently selected +/-1 tab is empty, is because the offScreenPageLimit of your ViewPager is 1 by default. All tabs above this threshold are re-created.

    Therefore, increasing the value will -- in your case -- cause all your tabs to appear empty after resuming. Check in your Fragment code which lifecycle methods you use to inflate your layout, set adapters and so forth, because that's what's causing your trouble.

提交回复
热议问题