我试图在程序中的两个片段之间传递数据。它只是存储在列表中的一个简单字符串。列表在片段 A 中公开,当用户单击列表项时,我需要它在片段 B 中显示。内容提供程序似乎只支持 ID,因此这不起作用。有什么建议么?
为什么不使用捆绑包呢?从您的第一个片段开始,设置方法如下:
Fragment fragment = new Fragment();
Bundle bundle = new Bundle();
bundle.putInt(key, value);
fragment.setArguments(bundle);
然后在第二个片段中,使用以下方法检索数据:
Bundle bundle = this.getArguments();
int myInt = bundle.getInt(key, defaultValue);
Bundle 为许多数据类型提供了 put 方法。请参见http://developer.android.com/reference/android/os/Bundle.html http://developer.android.com/reference/android/os/Bundle.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)