如何通过片段之间的数据片段、数据

2023-09-11 11:24:08 作者:逃离你心

我试着通过我的方案二片段(fragments)之间的数据。存储在列表它只是一个简单的字符串。这份名单是在一个片段公开,当用户点击一个列表项目,我需要它出现在片段B.内容提供商似乎只支持ID的,所以这是行不通的。有什么建议?

Im trying to pass data between two fragmens in my program. Its just a simple string that is stored in the List. The List is made public in fragments A, and when the user clicks on a list item, I need it to show up in fragment B. The content provider only seems to support ID's, so that will not work. Any suggestions?

推荐答案

我觉得片段之间的沟通应通过活动来完成。和碎片和活动之间的通信可以做这样的http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity.

I think communication between fragments should be done via activity. And communication between fragment and activity can be done this way http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity.