从这个fragment2传值到fragment4
fragment2中的代码:
public static void clickMoreBtn() {
// 实例化Fragment页面
fragmentPage4 = new FragmentPage4();
// 得到Fragment事务管理器
FragmentTransaction fragmentTransaction = act
.getSupportFragmentManager().beginTransaction();
// 替换当前的页面
fragmentTransaction.replace(R.id.frame_content, fragmentPage4);
// 事务管理提交
Bundle bundle = fragmentPage4.getArguments();
bundle.putString("userName",bundle.getString("userName"));
// Log.i("FragmentPage2",bundle.getString("userName"));
fragmentPage4.setArguments(bundle);
fragmentTransaction.commit();
fragment4中的代码:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle bundle = getArguments();
// Log.i("FragmentPage4",bundle.getString("userName"));
tx = (ImageView) getView().findViewById(R.id.index_my_list1_touxiang);
tv = (TextView)getView().findViewById(R.id.userName);
tv.setText(bundle.getString("userName"));
fragment2中的代码:
public static void clickMoreBtn() {
// 实例化Fragment页面
fragmentPage4 = new FragmentPage4();
// 得到Fragment事务管理器
FragmentTransaction fragmentTransaction = act
.getSupportFragmentManager().beginTransaction();
// 替换当前的页面
fragmentTransaction.replace(R.id.frame_content, fragmentPage4);
// 事务管理提交
Bundle bundle = fragmentPage4.getArguments();
bundle.putString("userName",bundle.getString("userName"));
// Log.i("FragmentPage2",bundle.getString("userName"));
fragmentPage4.setArguments(bundle);
fragmentTransaction.commit();
fragment4中的代码:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle bundle = getArguments();
// Log.i("FragmentPage4",bundle.getString("userName"));
tx = (ImageView) getView().findViewById(R.id.index_my_list1_touxiang);
tv = (TextView)getView().findViewById(R.id.userName);
tv.setText(bundle.getString("userName"));
解决方案 »
- achartengine 折线图 5个点只显示2个点的值,为什么?
- 类型转换
- 移植ntfs-3g到android
- 图片的保存问题若干
- ExpandableListActivity
- Android环境搭建
- 如何使用ANT进行多渠道循环打包“1个主项目3个资源项目组成的项目”
- android系统内存填充
- layout_weight You must supply a layout_width attribute
- android 一个app可以有多个 threadpool(线程池) 吗?
- 关于调用CHECKBOX
- 求教!本人Android小白,昨天遇到一个网络连接超时的问题,一直没解决,我已经设置了网络连接的权限,超时时间改成了一分钟,但还是不行,求大哥帮忙看看,跪求!
public static Fragment newInstance(int position) {
NewsFragment fragment = new NewsFragment();
Bundle bundle = new Bundle();
bundle.putInt("position", position);
fragment.setArguments(bundle); //setAraguments 传递一个bundler对象
return fragment;
}
把replace移到commit前一句
Bundle bundle = getArguments();
Log.i("FragmentPage2",bundle.getString("userName"));测试可以传过来,然后再传给下一个fragement,怎么传都传不过去
现在这种方式早都过时了,可以换种方式来实现。接口回调,或者livedatabus,又或者evenBus来做