Android的共享片段之间的数据 [英] Sharing data between android fragments

查看:160
本文介绍了Android的共享片段之间的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个片段。
checkNodesFragment 动态创建的复选​​框,然后的ArrayList
ReserveNodesFragment 应该访问哪个人在checkNodesFragment进行了检查。
哪些存储方法更好用,从而ReserveNodesFragment能看到查了一下复选框?

I have two fragments. The checkNodesFragment creates dynamically an ArrayList of checkBoxes and then the ReserveNodesFragment should access which of them were checked in checkNodesFragment. What storage method is better to use, so as ReserveNodesFragment can see what checkBoxes where checked?

搜索后,我发现的共享preferences 是永久存储数据的方法。是共享preferences适合通过做片段可见数据?
我在android的新手,很抱歉,如果这个问题是显而易见的。

After searching, i found that SharedPreferences is a method to store data permanently. Is SharedPreferences suitable for making data visible through fragments? I am newbie in android, so sorry if the question is obvious.

推荐答案

片段之间的通信应通过活动来完成。

The communication between fragments should be done via Activity.

创建一个包,并使用 fragment.setArguments(包)将数据传递到片段

Create a bundle and use fragment.setArguments(bundle) to pass data to Fragment.

创建一个接口片段,并在活动实施接口

create an interface in your fragment and in your Activity implement the interface

更多信息:

与其他片段通讯 (下载示例)。

Communicating with Other Fragments (Download the sample).

这篇关于Android的共享片段之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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