Fragment向Activity传值

2 篇文章 0 订阅
1 篇文章 0 订阅
通过回调接口实现fragment向父层的activity传值:
定义一个接口
public interface FullInfoInterface {
public void initFullInfo(Object o);
}

fragment中添加接口的对象
// 回调赋值给 Activity
FullInfoInterface fullInfoInterface ;

activity中实现具体传值的操作
FragmentManager fm ;
fm=getFragmentManager();
f1 = new ListFragment();
f1 .setFullInfoInterface( new FullInfoInterface() {
//datas为fragment要向activity传递的数据,initFullInfo实现activity用这些
//数据具体做什么
@Override
public void initFullInfo(Object datas) {
s =(String)datas;
toPlay_tv .setText( "test" + s );
}
});
fm.beginTransaction().replace(R.id. slidedetails_front , f1 ).commit();

fragment中在合适的位置实现对接口的回调
if ( fullInfoInterface != null ) {
fullInfoInterface .initFullInfo(datas);
}
就这样,自己摸索的。























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值