-1

I have a fragment that has a sliding tab layout and a view pager with 5 tabs. I start on tab 1, then, i push a different fragment to the back stack, replacing the fragment with the tabs. When, i now navigate back, the fragment with the tabs appears, but the first two tabs are empty (tab/fragment are not shown, but the views are created). If i navigate to the third tab and go back to tabs 1 and 2, the content appears again.

I tried to attach/show the fragment, but this didn't help.

any ideas?

This is the content of my tabs, they all look the same. The ViewClass is the same as well. It implements a Fragment for sure.

<?xml version="1.0" encoding="UTF-8" ?>
<Button
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="Navigate to 2"
    local:MvxBind="Click NavigateCommand" />

Rotation works as expected (if this information makes any difference.)

esskar
  • 10,000
  • 3
  • 31
  • 55
  • what PagerAdapter are you extending from? – Muhammad Babar Oct 06 '15 at 08:15
  • @MuhammadBabar i implemented my own from Android.Support.V4.View.PagerAdapter – esskar Oct 06 '15 at 08:18
  • What do you display in tabs 1 and 2? Some code who help us clear the picture – PunitD Oct 06 '15 at 08:47
  • since the viewpager preloads those 2 fragments, tab 1 to show it, tab 2 in memory for better performance, could it be that i have to "reset" the view pager? – esskar Oct 06 '15 at 09:22
  • 1
    This is how you can reset the pager http://stackoverflow.com/a/26859567/1939564 – Muhammad Babar Oct 06 '15 at 09:24
  • this helps. i tried to clear the pager on the ondestory of the fragment. and this helps to bring back everything when navigating back; but now it crashes during rotation since the activity is already destoryed, when the transaction is commited – esskar Oct 06 '15 at 10:54

2 Answers2

0

Have you set in your fragment with the sliding tab layout "setOffscreenPageLimit(5)" to your ViewPager?

yourViewPager.setOffscreenPageLimit(5);

I set this usually in the onCreateView(...)

Camino2007
  • 657
  • 7
  • 16
0

you can use a flag in onAttach() and onActivityCreated() in fragment. Checking that flag you can display the contents , here no need to set viewpager.setoffscreenlimit

Sangeet Suresh
  • 2,309
  • 15
  • 19