如何混合使用android.support.v4.app.Fragment和android.app.Fragment [英] How to mix android.support.v4.app.Fragment and android.app.Fragment

查看:172
本文介绍了如何混合使用android.support.v4.app.Fragment和android.app.Fragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试与标签一起使用com.here.android.mapping.MapFragment时遇到问题.

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

问题来了,因为不推荐使用TabActivity(我知道它仍然可以工作,但是需要一个面向未来的解决方案),并且FragmentTabHost似乎要求使用v4片段(如果该片段是从另一个片段派生的,则会崩溃) ),然后当我尝试在选项卡片段之一的布局中使用com.here.android.mapping.MapFragment时,由于(MapFragment)getFragmentManager().findFragmentById( )行出现错误,表示无法强制转换为MapFragment.

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.

我想问题是MapFragment是从android.app.Fragment派生的,而findFragmentById期望返回android.support.v4.app.Fragment的混合,所以问题就在于如何使这种混合物平稳运行在一起吗?

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 ?

推荐答案

android.support.v4.app.Fragmentandroid.app.Fragment类不能互换使用.

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

诺基亚创建了android.support.v4.app.Fragment的nofollow> com.here.android.mapping.MapCompatibilityFragment -如果您的应用程序使用支持片段,则使用它.

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

这篇关于如何混合使用android.support.v4.app.Fragment和android.app.Fragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆