android fragment 事件传递参数,Fragment跳转时传递参数及结果回传的方法(推荐)

今天总结一下Fragment间的参数传递及结果返回的方法。

效果图:

1、点击“加载第二个Fragment按钮”,加载出第二个Fragment,同时传递过去参数:“从Fragment1传来的参数”这几个String;

2、当用户点击第二个Fragment中的几个图片时,将点中的结果返回给第一个Fragment,将用户的选择在第一个Fragment显示出来

一、基本架构搭建

首先,我们要把整个架构搭起来,然后再进行参数传递和回传

(一)、基本XML构建:

根据上面的效果,大家很容易看到两个Fragment的布局:

1、Fragment1的布局:(fragment1.xml)

很简单,垂直布局,上面一个ImageView来盛装返回过来的图片结果,下面一个Button来用来点击加载第二个Fragment;

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ffffff"

android:orientation="vertical">

android:id="@+id/img_result"

android:layout_width="100dp"

android:layout_height="100dp"

android:scaleType="center"/>

android:id="@+id/load_fragment2_btn"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="加载第二个Fragment"/>

2、Fragment2的布局:(fragment2.xml)

这个也是垂直布局,上面的一个TextView用来盛装从Fragment1传过来的String参数,下面的几个ImageView用来显示几个供用户选择的图片

android:layout_width="match_parent"

android:layout_height="mat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值