我们如何将数据从活动发送到片段?使用FragmentPagerAdapter将片段配置为活动。
此致 迷你。
答案 0 :(得分:1)
setArguments
在创建时将包传递给片段。答案 1 :(得分:0)
您可以使用Bundle
执行此操作从活动(或片段)发送数据:
int a = 5;
Bundle args = new Bundle();
args.putInt("INT_DATA_TAG", a);
Fragment fragment = Fragment.newInstance(args);
//Making fragment transaction
检索片段中的数据
int a;
public static Fragment newInstance(Bundle args) {
a = args.getInt("INT_DATA_TAG"); //use a constant for the tag
return new Fragment();
}