简体   繁体   中英

Android: Get Parent View's Framelayout from Fragment inside TabHost

I have a FragmentActivity in which I am displaying two Fragments , Fragment A and Fragment B . In Fragment A I have another Fragment with Tabs. I have done this using classic TabHost . In this TabHost I have 2 more Fragments which has a ListView . Now what I want is on clicking on listitem I want to replace the content in Fragment B of parent FragmentActivity . Please help me to achieve this. I have tried the following till now.

1. View mContainer = (View)getActivity().findViewById(R.id.rightpane);
2. ViewGroup mContainer = (ViewGroup)getView().getParent();
3. Activity rrlist = ((RRPatientList)getParentFragment()).getActivity().getParent();
   View mContainer = (View) rrlist.findViewById(R.id.rightpane);

   ResultDetailView rdl = new ResultDetailView();
   rdl.setArguments(args);
   FragmentTransaction ft = getFragmentManager().beginTransaction();
   ft.replace(mContainer.getId(), rdl);
   ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);     
   ft.addToBackStack(null);
   ft.commit();

Nothing is working and I am getting either NullPointerException or No View Found for the ID ****** errors.

Please refer the screen shot for more info.

碎片

create method(like: updateFragment) in your activity to update fragment B. from fragment A's child fragment call that method(updateFragment) then that method(updateFragment) update fragment B.

here is answer for update fragment from activity - it 'll help you to update fragment B from your parent activity

here is answer for call activity method from fragment - it 'll help you to call parent activity method from fragment A's child fragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM