深入分析:Fragment与Activity交互的几种方式(二,使用Bundle)
2014-06-27 13:12
489 查看
首先我们需要在Activity中动态添加Fragment时,用Bundle封装我们需要传递的数据。
public void button(View view) {
ArgFragment arg = new ArgFragment();
Bundle bundle = new Bundle();
bundle.putString("arg", edit.getText().toString());
arg.setArguments(bundle);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.layout_fragment, arg);
ft.commit();
}
然后在Fragment的回调函数中通过Fragment提供的方法getArguments()取出Bundle对象。
text = (TextView) view.findViewById(R.id.text);
Bundle bundle = getArguments();
text.setText(bundle.getString("arg"));
针对本文也写了一个Demo,下载地址:http://download.csdn.net/detail/huangyabin001/7560031
点击打开链接
public void button(View view) {
ArgFragment arg = new ArgFragment();
Bundle bundle = new Bundle();
bundle.putString("arg", edit.getText().toString());
arg.setArguments(bundle);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.layout_fragment, arg);
ft.commit();
}
然后在Fragment的回调函数中通过Fragment提供的方法getArguments()取出Bundle对象。
text = (TextView) view.findViewById(R.id.text);
Bundle bundle = getArguments();
text.setText(bundle.getString("arg"));
针对本文也写了一个Demo,下载地址:http://download.csdn.net/detail/huangyabin001/7560031
点击打开链接
相关文章推荐
- 深入分析:Fragment与Activity交互的几种方式(二,使用Bundle)
- 深入分析:Fragment与Activity交互的几种方式(一,使用Handler)
- 深入分析:Fragment与Activity交互的几种方式(三,使用接口)
- 深入分析:Fragment与Activity交互的几种方式(一,使用Handler)
- 深入分析:Fragment与Activity交互的几种方式(一,使用Handler)
- 深入分析:Fragment与Activity交互的几种方式(三,使用接口)
- Fragment与Activity交互方式使用Bundle
- 在深入分析:Fragment与Activity一些互动的方式(一,使用Handler)
- Android Fragment与Activity交互的几种方式
- Fragment与Activity交互(使用Bundle)
- 深入分析:Android中app之间的交互(二,使用ComponentName)
- 数据绑定以及Container.DataItem几种方式与使用方法分析
- 深入分析:Android中app之间的交互(一,使用Action)
- Fragment基础点滴学习---Activity传递数据到Fragment(Fragment使用静态加载的方式)
- 在Activity之间使用Intent传值和Bundle传值的区别和方式
- Fragment与Activity交互(使用Handler)
- 数据绑定以及Container.DataItem几种方式与使用方法分析
- Fragment与Activity交互(使用接口)
- 在c#中使用HttpWebRequest时的几种提交数据方式学习和分析