Load Fragment using tablayout

Asked

Viewed 160 times

1

I have some Fragments with TableLayout, is in that order:

1, 2, 3, 4, 5, 6

I used the method viewPager.setOffscreenPageLimit(5) when I create mine viewPager.

So far ok, I don’t want him carrying around all the time Fragments and the seOffscreenPageLimit solved this for me. But I need the Fragment 1 recharge every time you reach it.

Does anyone have a solution for this? or have you ever suffered from something like this? Thank you

  • Can you explain the problem better? setOffscreenPageLimit(5), contrary to what he says, he keeps all the Ragments in memory. What he means by "reload"?

  • Exactly, it keeps all my Fragments in memory, and from what I’ve seen in the life cycle, it never gets into Fragment onCreateView, so far perfect. My problem is, I want to leave all Fragments in memory, I don’t need you logging into onCreateView, but I need Fragment 1 to always log into onCreateView for me to reload my webview.

  • Create a method in the given Fragment and put in it the code that reloads the Webview. Use the answer code of thiagoms83 and when this page is selected call this method.

1 answer

0

You can use the setOnPageChangeListener method from Viewpager to know when the user is at position 1:

viewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int arg0) {
            //verifique se usuario esta na posicao 0 e atualize o fragment
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {}

        @Override
        public void onPageScrollStateChanged(int arg0) {}
    });
  • I don’t understand where I can implement this, currently I have a setupViewPager and call an Adapter, I put this code on the Adapter?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.