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

后端 未结 3 947
遇见更好的自我
遇见更好的自我 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:13

    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());
        // ...
    }
    

    }

提交回复
热议问题