如何将数据片段传递给Android Studio中的其他片段活动

时间:2018-10-17 07:28:20

标签: android

SectionFragment.class

Intent subjectDetail = new Intent(getContext(), GradeFragment.class);
        ListGradeData clickItem = sectionList.get(position);

        subjectDetail.putExtra(EXTRA_SECTION_ID, String.valueOf(clickItem.getSectionId()));
        startActivity(subjectDetail);

GradeFragment.class

String studSectionId = getActivity().getIntent().getExtras().getString(EXTRA_SECTION_ID);
        Toast.makeText(getContext(), studSectionId, Toast.LENGTH_LONG).show();

它不显示studentSectionId。当我运行该应用程序时,单击按钮后它总是崩溃

1 个答案:

答案 0 :(得分:0)

对于片段,请使用FragmentManager添加/替换片段。并创建发送数据,例如

MyFragment myFragment = new MyFragment();

Bundle args = new Bundle();
args.putInt("someInt", someInt);
myFragment.setArguments(args);