Reputation: 71
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
Upvotes: 4
Views: 3765
Reputation: 1271
Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_main_container);
if (fragment != null) {
((TabLayoutFragment)fragment).tabClickDisable();
}
Upvotes: 0
Reputation: 71
I could finally solve it this way, in fragA
:
FragB parentFragment = (FragB) getChildFragmentManager()
.findFragmentByTag("detallesFragBusqueda");
if (parentFragment != null) {
parentFragment.consultaWS("", "AllPdf");
}
Upvotes: 3
Reputation: 157
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
Upvotes: 0
Reputation: 2792
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();
Upvotes: 0
Reputation: 6699
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.
Upvotes: 0