Android的共享片段之间的数据 [英] Sharing data between android fragments
问题描述
我有两个片段。
在 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屋!