4

I have a fragment(this is one tab of my tabhost) "fragA" inside other fragment "fragB" but I need to call one method of "fragB" from "fragA". when I do from an activity, I do this:

FragB detailsFragment=(FragB)getSupportFragmentManager().findFragmentById(R.id.detailFragment);

detailsFragment.consultaWS(convertIntWebService(categoria),"Pdf");

please, help me

Ravi.
  • 674
  • 2
  • 9
  • 21
marcoms10
  • 71
  • 1
  • 5

5 Answers5

3

I could finally solve it this way, in fragA:

FragB parentFragment = (FragB) getChildFragmentManager()
                                      .findFragmentByTag("detallesFragBusqueda");
if (parentFragment != null) {
    parentFragment.consultaWS("", "AllPdf");
}
Blo
  • 11,903
  • 5
  • 45
  • 99
marcoms10
  • 71
  • 1
  • 5
0

Your activity should facilitate all communication between fragments. Just create a method in your Activity that a fragment can call, which will tell another fragment to do something.

ashishduh
  • 6,629
  • 3
  • 30
  • 35
0

If FragA is inside FragB, you can do the same from within your FragA.

 FragB parentFragment = (FragB)getActivity().getSupportFragmentManager().findFragmentById(R.id.detailFragment);
 parentFragment.fragmentBMethod();
ILovemyPoncho
  • 2,762
  • 2
  • 24
  • 37
0

Read this http://developer.android.com/training/basics/fragments/communicating.html. This document explains that how can you communicate between Activity and Fragment and also between 2 Fragments

zeshanbaig786
  • 157
  • 11
0
Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_main_container);
if (fragment != null) {      
       ((TabLayoutFragment)fragment).tabClickDisable();
}
LBes
  • 3,366
  • 1
  • 32
  • 66
Rishabh Mahatha
  • 1,251
  • 9
  • 19