How call method in Fragment from FragmentTabHost

61 views Asked by At

i have a activity (that extends from AppCompatActivity ) with a FragmentTabHost.. in the onCreate of this activity, I make something like :

mTabHost = (FragmentTabHost)findViewById(R.id.tabhostReporte); mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Labores", ContextCompat.getDrawable(this, R.drawable.pala_azul)),Fragment_Labores.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Empleados", ContextCompat.getDrawable(this,R.drawable.people)), Fragment_Empleados.class, null);

I need call a method in Fragment_Labores and Fragment_Empleados from the activity but i don't know how to.. I mean, reading others say that getSupportFragmentManager().findFragmentByTag("tab2") but return null.

1

There are 1 answers

0
AChez9 On

That 'tag' you add in the TabHost.newTabSpec isn't actually the tag associated with the fragment (that would make too much sense).

Unfortunately, without creating some custom classes, the easiest way to retrieve what you are looking for is probably something like 'getSupportFragmentManager().findFragmentByTag( "android:switcher:" + R.id.pager + ":" + mViewPager.getCurrentItem())'