FragmentTabHost & Fragments - How do I pass data between tabs?

后端 未结 3 941
遇见更好的自我
遇见更好的自我 2020-12-19 13:45

I have a MainActivity (FragmentActivity) that has a FragmentTabHost.

public class FragmentTabs extends FragmentActivity {
    private FragmentTabHost mTabHos         


        
3条回答
  •  悲&欢浪女
    2020-12-19 14:02

    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();
    

提交回复
热议问题