0

I have a Viewpager that uses a FragmentStatePagerAdapter. Each page is a Fragment. My pages contains an linearlayout (llTags) which is default visible.

If the user clicks on a page (main layout of the fragment), the linearlayout must be invisible (works) but the other linearlayouts (llTags in other pages) needs to be changed too.

If i click, the visibility of the linearlayouts changed off all pages exept the previous and next. This is because the getItem from the adapter isn't called for the next/previous item again. How can i notify these pages.

ps: i have a newInstance method and a public void setTagslayoutVisible(boolean) for changing the visibility from the adapter.

Francesco verheye
  • 1,574
  • 2
  • 14
  • 32

1 Answers1

0

Next and previous are already loaded and the adapter is not going to call creation.

Take a quick try at this, in your adapter get function if your fragment is already loaded it returns those objects. So just add something like this

if(myMap.containsKey(position))
{
      LiveStreamFullScreenFragment lfsf = (LiveStreamFullScreenFragment) myMap.get(position));
      lfsf.setShowTags(mShowTags);
      return lfsf;
} else
{

and in your fragment class

public void setShowTags(boolean showtags)
{
    mShowTags = showtags;
    if(!mShowTags)
    {
         llLiveStreamTags.setVisibility(View.GONE);
    }
}

Hope this helps and enjoy your work.

Marko Lazić
  • 883
  • 7
  • 9