getChildFragmentManager() and support libraries

那年仲夏 提交于 2019-12-18 03:17:09

问题


I am using the getChildFragmentManager() in an app that is compiling against API level 19, with the minimum SDK set to 14.

getChildFragmentManager() was introduced in API 17, so devices running at API levels 14, 15, or 16 will throw a NoSuchMethodError when the method is called.

I did look through all the other StackOverflow questions regarding this issue, but none of them seem to answer this question: is there any way to get the getChildFragmentManager() method to work on devices pre-API level 17? If so, how?

The method does not seem to be included in either the v4 or v13 support libraries. I have tried clean builds with both v4 and v13 support libraries, but that does not seem to solve the issue.


回答1:


is there any way to get the getChildFragmentManager() method to work on devices pre-API level 17? If so, how?

Use the backport of fragments from the Android Support package (android-support-v4.jar, android.support.v4.app.Fragment).

The method does not seem to be included in either the v4 or v13 support libraries.

Yes, it is, on FragmentActivity, the Activity base class you need to use in order to use the fragments backport.

It is on the Fragment class from the backport, for managing child fragments of that fragment.

I have tried clean builds with both v4 and v13 support libraries, but that does not seem to solve the issue.

Either you did not change to FragmentActivity the Fragment backport, or your support library JARs are old. Here is a sample project demonstrating the use of FragmentActivity the Fragment backport and its getChildFragmentManager().




回答2:


You could try the SupportFragmentManager instead:

yourFragment = (YourFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.playListFragment)


来源:https://stackoverflow.com/questions/23640066/getchildfragmentmanager-and-support-libraries

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