0

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.

Fragments

harsha.cs
  • 122
  • 2
  • 13

1 Answers1

0

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

Community
  • 1
  • 1
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
  • But how to get ``FragmentActivity`` from ``ListFragment`` of ``TabHost``. Your code works when only there are two levels hierarchy (FragmentActivity -> Fragment), but I have FragmentActivity -> Fragment -> Fragment. How to achieve in this scenario? – harsha.cs Dec 21 '15 at 19:48
  • 1
    same scenario work for n level of fragment because you are adding all fragment in one parent activity am i right?? then base is ACTIVITY. so you can call activity method from any fragment. – Dhaval Parmar Dec 21 '15 at 19:51