How to mix android.support.v4.app.Fragment and android.app.Fragment

北城余情 提交于 2019-12-01 04:08:26

问题


I'm having a problem with com.here.android.mapping.MapFragment when trying to use it with tabs.

The issue comes that since the TabActivity is deprecated(I know it still works, but need a future proof solution), and FragmentTabHost appears to be requiring the v4 fragment to be used (it crashes if the fragment is derived from other one) , then when I try having the com.here.android.mapping.MapFragment used in a layout of one of the tab fragments, then I can not retrieve it for the required initialization, since the (MapFragment) getFragmentManager().findFragmentById() line has error indicating that the casting to MapFragment can not be made.

I suppose the issue is that MapFragment is derived from android.app.Fragment and the findFragmentById expects to return mix android.support.v4.app.Fragment, so the question would be on how could I get this mixture to run smoothly together ?


回答1:


The android.support.v4.app.Fragment and the android.app.Fragment classes can't be used interchangeably.

Nokia have created com.here.android.mapping.MapCompatibilityFragment which extends android.support.v4.app.Fragment - use that instead if your app uses support fragments.



来源:https://stackoverflow.com/questions/22294506/how-to-mix-android-support-v4-app-fragment-and-android-app-fragment

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