fragment之间的参数传递
2014-10-24 23:49
260 查看
使用Fragment的时候可能需要在两个Fragment之间进行参数的传递,找到一个方法就能实现像Activity一样便捷的实现参数传递 程序中的一段代码
Restart sf = new Restart(this.getActivity(),w,h);
Bundle bundle = new Bundle();
bundle.putString("second",second+"" ); //second 为一个数字,将它变成string
bundle.putString("count",count+"" );
sf.setArguments(bundle);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.container, sf);
transaction.commit();
可以使用bundle进行参数传递,这样在两个Fragment跳转的时候就可以带上参数了,在另外一个Fragment获取参数的方式只需要一个语句
String second = getArguments().getString("second");
String count = getArguments().getString("count");
TextView tv=(TextView)view.findViewById(R.id.score);
tv.setText(second+":"+(100-Integer.parseInt(count)))
second和count是自己定义的一个标识,参数的形式只要bundle能传递都可以实现
Restart sf = new Restart(this.getActivity(),w,h);
Bundle bundle = new Bundle();
bundle.putString("second",second+"" ); //second 为一个数字,将它变成string
bundle.putString("count",count+"" );
sf.setArguments(bundle);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.container, sf);
transaction.commit();
可以使用bundle进行参数传递,这样在两个Fragment跳转的时候就可以带上参数了,在另外一个Fragment获取参数的方式只需要一个语句
String second = getArguments().getString("second");
String count = getArguments().getString("count");
TextView tv=(TextView)view.findViewById(R.id.score);
tv.setText(second+":"+(100-Integer.parseInt(count)))
second和count是自己定义的一个标识,参数的形式只要bundle能传递都可以实现
相关文章推荐
- android中传递复杂参数,activity之间和fragment之间的bundle传递集合/对象
- 两个Fragment之间参数的传递
- 两个Fragment之间参数的传递
- Android中Fragment之间的通信和参数传递
- Android进阶之Fragment和Activity之间通过setArguments传递复杂参数
- 两个Fragment之间参数的传递
- android fragment传递参数_fragment之间传值的两种方法
- Android Fragment之间参数传递通过Activity中的变量
- Android Fragment之间参数传递通过使用bundle进行参数传递
- 代码总结:Fragment之间传递参数和Fragment返回上一个Fragment传回数据
- android中传递复杂参数,activity之间和fragment之间的bundle传递集合/对象
- 两个Fragment之间参数的传递
- android中传递复杂参数,activity之间和fragment之间的bundle传递集合/对象
- Fragment之间传递参数
- 两个Fragment之间参数的传递 .
- 两个Fragment之间参数的传递
- Fragment之间的参数的传递
- Android——软键盘操作+fragment之间传递参数+TextView限制字数,显示"..."
- ANDROID FRAGMENT传递参数_FRAGMENT之间传值的两种方法
- (转)Activity与Fragment之间传递参数