通过回调接口实现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);
}
就这样,自己摸索的。