I'm using an nested fragment which is of class Fragment, as opposed to SupportFragment (v4).
I should use getChildSupportManager to handle this properly, but that suspects v4 support fragments, and I have a regular Fragment (which I can't change, it comes from a library).
How would I be able to solve this?
I should use getChildSupportManager to handle this properly, but that suspects v4 support fragments
AFAIK, there is no getChildSupportManager() method in Android. There is getChildFragmentManager().
If you are using getChildFragmentManager() from a FragmentActivity, you need to give it a fragment from the Android Support package backport (android.support.v4.app.Fragment). If you are using getChildFragmentManager() from a regular Activity on API Level 17+, you need to give it a native fragment (android.app.Fragment).
I have a regular Fragment (which I can't change, it comes from a library).
Then set your minSdkVersion to 17 and use Activity instead of FragmentActivity.
Related
I've got a problem with fragments. I want to create different fragment files, which are connected and displayed in a framelayout inside my mainactivity. Also, it should be possible to switch the fragments with a bottom navigation view.
I created different fragment(blank) classes and they extend the class Fragment, but I'm not able to give these instances of this classes as a parameter to a method called setFragment(Fragment fragment).
Do you know what could cause this problem? My classes extend the class Fragment and so it should be possible to give my own created fragment classes, shouldn't it? +
Thanks for your help!
The solution to your problem is to make your fragments extend android.app.Fragment instead of Fragment. Everything should work fine after that.
However, you need to understand the difference between android.app.fragment and android.support.v4.app.Fragment.
If your app uses fragments and you want to support devices before API 11, you have to use android.support.v4.app.Fragment. However, if you're only targeting devices running API 11 or above, you can use android.app.Fragment.
There are two different kinds of fragments
android.app.Fragment
and
android.support.v4.app.Fragment
Use app fragments with android.app.FragmentManager
Use support fragments with android.support.v4.app.FragmentManager
It can be obtained by getSupportFragmentManager() of android.support.v4.app.FragmentActivity
I am trying to use getChildFragmentManager() method on api 14, but of course I am getting error. Is there anyway to use this method on lower apis.
Thanks
To use nested fragments on API Level 16 and below, you need to use the fragments backport from the support-v4 or support-v13 portion of the Android Support package. This, in turn, requires you to inherit from FragmentActivity and have your fragments inherit from android.support.v4.app.Fragment. Then, you can call getChildFragmentManager() to use nested fragments.
To someone that appeared here by a search on Google
I was having a similar problem using DialogFragment
The problem was because I was importing android.app.DialogFragment instead of android.support.v4.app.DialogFragment
DialogFragment or not, be sure that you are importing the right libs :)
I started creating my app with min SDK 15 and I used the v4 support library for the fragments and the fragment manager and fragment transaction etc. When I decided to use card animations, I figured I had to switch to using the fragments without the support library. But when I did this, once I press the back button, the whole app closes instead of returning to the previous view. What could be the cause of this?
I fixed the issue by extending only activity instead of the support deprecated ActionBarActivity.
I started to change my App to Material design.
I´ve changed my Activity to ActionBarActivity and My Theme to AppCompat, to be able to color ActionBar and use AppCompat Navigation drawer.
I´m switching Fragments in my Activity, which are added to backstack throught
getSupportFragmentManager()
.beginTransaction()
.replace(...)
.addToBackStack(null)
.commit();
I have to use SupportFragmentManager because of AppCompat. Therefore, I have to use android.support.v4.app.Fragment from support library.
Problem:
I´m also using PreferenceFragment, which is not included in support library. And therefore, I can´t add the fragment to backstack.
Error: The method replace(int, Fragment, String) in the Type FragmentTransaction is not applicable for the Arguments (int, SettingsFragment, String)
The solution I'm using right now is this library. I don't want to use it, because I'm targeting API 14.
Is there a way I can use PreferenceFragment with SupportFragmentManager?
No, support FragmentManager accepts only support Fragments and there is no way you can use fragments from android.app package.
BTW, I suggest you to use this library instead. It has minSdkVersion of 7, but it has recent updates and I think it's more stable than the library you're currently using.
Use PreferenceFragmentCompat from preference-compat-v7 support library. These objects can be handled by SupportFragmentManager.
I am trying to use getChildFragmentManager() method on api 14, but of course I am getting error. Is there anyway to use this method on lower apis.
Thanks
To use nested fragments on API Level 16 and below, you need to use the fragments backport from the support-v4 or support-v13 portion of the Android Support package. This, in turn, requires you to inherit from FragmentActivity and have your fragments inherit from android.support.v4.app.Fragment. Then, you can call getChildFragmentManager() to use nested fragments.
To someone that appeared here by a search on Google
I was having a similar problem using DialogFragment
The problem was because I was importing android.app.DialogFragment instead of android.support.v4.app.DialogFragment
DialogFragment or not, be sure that you are importing the right libs :)