[英]Possibility of casting android.support.v4.app.Fragment to android.app.Fragment when implementing a FragmentTabHost
I want to implement a three tab screen inside a fragment (TabFragement). 我想在片段(TabFragement)内实现三个选项卡的屏幕。 I am importing
android.support.v4.app.FragmentTabHost
and android.support.v4.app.Fragment
when creating a tabhost inside the fragment. 在片段内创建TabHost时,我正在导入
android.support.v4.app.FragmentTabHost
和android.support.v4.app.Fragment
。
When I try to call the fragment (TabFragement) using an activity, in 当我尝试使用活动调用片段(TabFragement)时,
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
the method 'replace' wants to have a fragment of android.app.Fragment. 方法“替换”希望包含android.app.Fragment的片段。
So, how should I solve this matter? 那么,我该如何解决呢?
Any sugegstions? 有任何建议吗?
Thank you. 谢谢。
To solve the import problem you need to extends FragmentActivity
. 要解决导入问题,您需要扩展
FragmentActivity
。 FragmentActivity
was added to allow the use of Fragments
from the support library in your Activities
. 添加了
FragmentActivity
以允许使用“ Activities
”中支持库中的Fragments
。
Also, make sure you use getSupportFragmentManager()
instead. 另外,请确保使用
getSupportFragmentManager()
代替。
i think you have to take only Fragment instead FragmentTabhost and add tabhost to your fragmentlayout.xml and in fragment.java class take that tabhost object and create tabbar. 我认为您只需要使用Fragment而不是FragmentTabhost并将tabhost添加到fragmentlayout.xml,并在fragment.java类中使用该tabhost对象并创建tabbar。 thats it...
而已...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.