Android Honeycomb, get instance of Fragments?

余生颓废 提交于 2019-12-10 23:44:02

问题


I have a PreferenceActivity that loads two Fragments via the xml file for the headers.

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.

What do I do?


回答1:


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.




回答2:


Did you manage to do that?

Just did so using the line:

Fragment shown = getSupportFragmentManager().findFragmentById(R.id.frgHome);


来源:https://stackoverflow.com/questions/5908492/android-honeycomb-get-instance-of-fragments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!