You should write a method in the parent (containing ViewPager and sub-fragments) as follows:
public void setPagerFragment(int a) { pager.setCurrentItem(a); }
This will set the current fragment in the ViewPager to the specified. Then you can call this method from the child fragment with:
int newFrag = 0;
As for sending additional data with a request for showing on a new fragment, you can make another method in the parent, which should be called in the child element, which will set some data in the parent object, which then can use the parent element when setting up the new fragment.
For example, in the parent object:
public void setExtraData(Object data) { dataFromChildFrag = data; }
And use this in the child like this:
String data = "My extra data";
Finally, if the parent is actually the fragment itself, and not the activity, just replace all the links:
ParentActivity parent = (ParentActivity) getActivity();
in
ParentFragment parent = (ParentFragment) getParentFragment();
Hope this helps!
Luke
source share