I want to access a parent Fragment views in a child fragment which is attached with a View Pager. Means Parent Fragment contains a View Pager and View Pager then have a Fragment, and I want to use Parent Fragment Views in current Fragment of Pager.
Parent Fragment---->(Contains)View Pager------>(Contains)Child Fragment. Child Fragment wants to use Parent Fragment multiple views. Please suggest any solution regarding the same.
Thanks in advance.
in your child fragment use:
ParentFragment frag = ((ParentFragment)this.getParentFragment());
and in your parent fragment you can store the references of your required views and use getter setter to access them, another solution is creating a listener interface. follow below link to find out how to implement:
http://developer.android.com/training/basics/fragments/communicating.html
Inside Parent Fragment
ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager())
make sure it is getChildFragmentManager()
and inside the child fragment, to access anything from parent fragment
((ParentFragment)this.getParentFragment()).any_thing_inside_parent_fragment;
You can use the below code.
FloatingActionButton fab = getParentFragment().getView().findViewById(R.id.menu_item);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With