[英]Is there a way to convert fragment to android.support.v4.app.Fragment
my app requires to use both android.support.v4.app.Fragment and default fragment which has support from API 11 onwards, can anyone tell me how to cast the default API 11 Fragment to android.support.v4.app.Fragment?. 我的应用程序需要同时使用android.support.v4.app.Fragment和从API 11开始具有支持的默认片段,谁能告诉我如何将默认API 11 Fragment转换为android.support.v4.app.Fragment?
Is it possible?, in my app i need to use settingsfragment, this does not support android.support.v4.app.Fragment. 有可能吗?在我的应用程序中,我需要使用settingsfragment,这不支持android.support.v4.app.Fragment。 Any help 任何帮助
Thanks 谢谢
There is no way to do a cast as you want. 您无法根据需要进行转换。 Try to do that: 尝试这样做:
if (Build.VERSION.SDK_INT >= 11)
{
// user fragment
}
else
{
// user android.support.v4.app.Fragment
}
Can anyone tell me how to cast the default API 11 Fragment to android.support.v4.app.Fragment? 谁能告诉我如何将默认的API 11片段转换为android.support.v4.app.Fragment?
This is not possible because android.support.v4.app.Fragment is completely different class than the framework's fragment class and even when android.support.v4.app.Fragment run on Android 3.0 or above, its implementation is still used; 这是不可能的,因为android.support.v4.app.Fragment是与框架的fragment类完全不同的类,即使android.support.v4.app.Fragment在Android 3.0或更高版本上运行,其实现仍会使用; it does not try to switch to the framework's implementation. 它不会尝试切换到框架的实现。
Is it possible?, In my app I need to use settingsfragment, this does not support android.support.v4.app.Fragment? 有可能吗?,在我的应用中,我需要使用settingsfragment,这不支持android.support.v4.app.Fragment?
You can't use the current implementation of framework's PreferenceFragment , but you can use this library that maintains compatibility layer for Android 1.6 and up and it's PrefrenceFragment inherits from android.support.v4.app.Fragment not the framework's one. 您不能使用框架的PreferenceFragment的当前实现,但是可以使用此库来维护Android 1.6及更高版本的兼容性层,并且PrefrenceFragment继承自android.support.v4.app.Fragment而不是框架的库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.