如何将字符串对象从一个片段传递到另一个片段android?

时间:2016-09-05 03:12:22

标签: android

有一种内置方法可以将字符串或字符串数​​组从一个片段传递到另一个片段。 如何将字符串对象从一个片段传递到另一个片段?

1 个答案:

答案 0 :(得分:0)

从片段发送字符串

DiagnosticListFragment fragmentS1 = new DiagnosticListFragment();
                            FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
                            Bundle bundle = new Bundle();
                            bundle.putString(Constants.BundleConstants.USER_ID,user_id);
                            fragmentS1.setArguments(bundle);
                            // Store the Fragment in stack
                            transaction.addToBackStack(null);
                            transaction.replace(R.id.fragment_parent, fragmentS1).commit();

如何收到其他片段:

final Bundle bundle = getArguments();
        String user_id;

        if(bundle != null) {
            user_id =  user_id = bundle.getString(Constants.BundleConstants.USER_ID);
        }
相关问题