I have a MainActivity (FragmentActivity) that has a FragmentTabHost.
public class FragmentTabs extends FragmentActivity {
private FragmentTabHost mTabHos
You can get your fragment like this:
YourFragment frag = (YourFragment) getSupportFragmentManager()
.findFragmentById(R.id.fragmentid));
To send data to a fragment you can follow this approach, creating a new transaction and sending the data through a bundle.
Bundle arguments = new Bundle();
arguments.putString("some id string", "your data");
YourFragment fragment = new YourFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction().add(R.id.fragmentid, fragment).commit();
This can be accomplished by the 3rd argument of android.support.v4.app.FragmentTabHost.addTab(TabSpec, Class, Bundle args), then the args can be retrieved via android.support.v4.app.Fragment.getArguments()
public class Tab1Fragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// do something with the arguments
Log.i("DEBUG", "" + getArguments());
// ...
}
}
OP here. To solve this problem I have overloaded the onAttachFragment method in my FragmentActivity:
public class FragmentTabs extends FragmentActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
}
@Override
public void onAttachFragment(Fragment fragment) {
super.onAttachFragment(fragment);
if (fragment.getClass() == ClassA.class) {
ClassA mClassAFragment = (ClassA)fragment
...
}
}
}