Fragment的传值跳转

//传值

//传值跳转
MainActivity activity = (MainActivity) getActivity();
FragmentManager supportFragmentManager = activity.getSupportFragmentManager();
//开启事务
FragmentTransaction transaction = supportFragmentManager.beginTransaction();
FragmentTwo two=new FragmentTwo();
//利用Bundle传值
Bundle bundle=new Bundle();
bundle.putString("name",name);
bundle.putString("password", password);
two.setArguments(bundle);
transaction.replace(R.id.frame,two,"two");
transaction.commit();
//接受值

Bundle arguments = getArguments();
String name = arguments.getString("name");
String password = arguments.getString("password");
tv_name.setText("姓名:" + name);
tv_password.setText("密码:" + password);


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