简体   繁体   中英

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?.

Is it possible?, in my app i need to use settingsfragment, this does not support 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?

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; 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM