Android蜂窝,得到碎片的实例? [英] Android Honeycomb, get instance of Fragments?
问题描述
我有通过为标题中的XML文件加载两个片段一个preferenceActivity。
I have a PreferenceActivity that loads two Fragments via the xml file for the headers.
我似乎不能够设置一个标记或标识。或在头的XML片段的标记(即使用loadHeaderFromResource(加载);
I don't seem to be able to set a tag or an ID. or a tag for the fragments in the header xml (that is loaded using loadHeaderFromResource();
由于我不实例化它自己,我没有身份证。或参考弄个。
Since I don't instantiate it myself I have no ID. or reference to get hold of it.
我该怎么办?
推荐答案
我不认为通过XML加载都给予了标签preference碎片,据我所知他们没有一个已知的ID,所以唯一的办法要做到这一点的可以的是(1)保持一个单独的列表<的WeakReference<片断>>
在 preferenceActivity
,并添加到该列表中的活动的 onAttachFragment
(2)后来,看在该列表中,当你需要找到一个特定的片段
I don't think preference fragments loaded via XML are given a tag, and AFAIK they don't have a known ID, so the only way to do this may be to (1) maintain a separate List<WeakReference<Fragment>>
in your PreferenceActivity
and add to that list in the Activity's onAttachFragment
and (2) later on, look in that list when you need to find a particular fragment.
这篇关于Android蜂窝,得到碎片的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!