在MainActivity中设置发送的信息,在fragment中接收,
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btn:
Bundle bundle= new Bundle();
bundle.putString("message","我喜欢学习");
BlankFragment1 bf = new BlankFragment1();
bf.setArguments(bundle);
replaceFragment(bf);
break;
case R.id.btn2:
replaceFragment(new ItemFragment());
}
}
BlankFragment1
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getArguments();
String s=bundle.getString("message");
Log.d("li", "onCreate: "+s);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
标签:getString,Fragment,Activity,Bundle,getArguments,bundle,发送信息,BlankFragment1,onCre
From: https://www.cnblogs.com/lin513/p/17311412.html