使用Bundle在fragment之间传递数据

Fragment_personal_history_record fragment = new Fragment_personal_history_record(); //声明要跳转的fragment对象
Bundle bundle = new Bundle();//声明一个Bundle对象
bundle.putString("person",list.get(position).getAllMessage());   //用Bundle对象携带需要传递的信息
fragment.setArguments(bundle);   //将bundle对象绑定到fragment,下边就是fragment的正常切换了
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.huiyuanIntergace,fragment);
transaction.addToBackStack(null);
transaction.commit();
 
  
 
  
//在目标fragment中则使用如下命令获取传递过来的信息
Bundle bundle = getArguments();
String s = bundle.getString("person");//person 是之前设置好的key,此处为取出person对应的内容

你可能感兴趣的:(Android,studio开发)