如何从一个片段传输到另一个片段机器人 [英] How can I transfer data from one fragment to another fragment android

查看:106
本文介绍了如何从一个片段传输到另一个片段机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,就是通过activity.We可从碎片将数据发送到活动,活动片段的方法之一是有没有其他办法。

One way I know that is through activity.We can send data from fragment to activity and activity to fragment Is there any other way.

推荐答案

从一个片段数据传递到另一个捆绑将有所帮助。

To pass data from one fragment to another Bundle will help.

LifeShapeDetailsFragment fragment = new LifeShapeDetailsFragment(); //  object of next fragment
Bundle bundle = new Bundle();
bundle.putInt("position", id);
 fragment.setArguments(bundle);

然后推/呼叫下一个片段。

和code到下一个片段:

and code to next Fragment:

Bundle bundle = this.getArguments();
int myInt = bundle.getInt("position", 0);

这篇关于如何从一个片段传输到另一个片段机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆