0

What i am doing is showing Fragment in view pager and has Gesture detector implemented on Whole view. When we touch the View i want to hide some layouts from current fragment and all other fragments in view pager.

But problem is this that view pager automatically generates next and previous view and when i swipe to next view it does not hide those layouts but other Fragments other than its consecutive ones Layouts are Gone.

How do i refresh consecutive fragments of view pager from fragment itself.

Thanx in advance.

Ramkesh Yadav
  • 987
  • 2
  • 11
  • 16

2 Answers2

0

You should have an activity that control that ViewPager and detects what Fragments to display. That's the place to update the fragments.

Use the OnPageChangeListener listener and inform the fragment of the change.

If you want to do it from the Fragment itself, try onStart() or onResume()

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
0

Fragments can be notified of events, so they can take actions accordingly.

One way of doing this would be using a broadcast like in ViewPager Activity to notify a Fragment of a specific event

Other way is like @Antonio said, making it on the OnPageChangeListener (I suppose that would be a lot cleaner).

Community
  • 1
  • 1
Logain
  • 4,259
  • 1
  • 23
  • 32
  • i am using OnPageChangeListener like this and calling fragment method to change the visibility of Views but it gives NPE @Override public void onPageSelected(int arg0) { Fragment frag = adapter.getItem(arg0); ((PageFragment) frag).changeVisibility(MainActivity.this); } – Ramkesh Yadav Feb 06 '15 at 10:12
  • Where does it throw NPE? I mean, which of those is null? – Logain Feb 06 '15 at 10:15
  • Layouts that i want to hide commonData = (CommonData) context.getApplication(); if (commonData.isViewHidden) { bottomRL.setVisibility(View.GONE); actionBarRL.setVisibility(View.GONE); } else { bottomRL.setVisibility(View.VISIBLE); actionBarRL.setVisibility(View.VISIBLE); } bottomRL and actionBarRL are null – Ramkesh Yadav Feb 06 '15 at 10:16
  • well, you might have another issue there. Can you edit your post with a more in depth example with code? – Logain Feb 06 '15 at 10:28