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 :)
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 :)
My app minimum version is 10
and till now i am using the support library for fragments
Now i want to add the flip animation for few fragment transition
So as per the android guide we need to use the animator for that
and it has support from the api level 11 which is no issue for me.
but also need to use the getFragmentManager instead getSupportFragmentManager
So i removed the support library changed my minimum version 10 to 11 errors are coming
because in my app i have FragmentTabhost and getChildFragmentManager().
FragmentTabHost only available on support library and to set FragmentManager using the getChildFragmentManager it wont allow me to do that because it requires api level 17
any help appreciated.
Let me know if you need more details
Thanks in advance.
use android.support.v4.fragment instead of android.app Fragment in your project
and you can use following snippet for animation while adding/replacing fragment
getSupportFragmentManager().beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.fragment, new FragmenntTwo())
.commit();
where FragemntTwo() is the fragment you are inflating.Here you can use your custome animation as well by replacing setTransition(..) with setCustomAnimations(..)
I think coding Animation for API level 10 and below is challenging, and rather obsolete. I can give one suggestion, read web page # NineOldAndroids from the active developer Jake Wharton. It supports Android 1.0 and up, though deprecated with new Android libraries. So one lesson is that it would be easier for you to create a new project, basically start over instead of converting code.
Even if you do use existing animation like ValueAnimator, the API level is 11 and up. You're hitting that boundary between level 10 and 11 for animation.
Good luck and keep us posted.
Custom animation works with Support Fragment manager too. you will be able to use the support fragment manager and still animate it.
For FragmentTabhost ,I used to build a program with app.Fragment,but suddenly my PM told me he want to use ViewPager +Fragment. What i did was copy the FragmentPagerAdapter.class from v4.jar and replace all these v4.Fragment with app.Fragment.I think this may help you.
And for getChildFragmentManager(), #SuppressLint("NewApi") may help you.
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.
I've got a project written for API 11 and up, no I need it available for 2.3.3 OS devices either, so need to use Support Library. What is the easiest way to go with it? I know some methods have different names for Fragments, for instance. Can it be possible to use "Find and Replace All"?
For the most part, yes it will be possible. You'll also have to change less than you think, for example the Fragment class is fine.
You will have to change getFragmentManager to getSupportFragmentManager, as well as changing your base Activity to a FragmentActivity. Those are the most common two off the top of my head.
The easiest way is to change the target to 2.2, add the support-package as a library, and see what breaks and then fix it-- and once you have a replacement fix you can use find and replace all to fix all instances of the issue.
Can it be possible to use "Find and Replace All"?
As far as I'm concerned, it's never a good idea to do a simple "Find and Replace All"... it's far too easy to make a mistake.
What is the easiest way to make the transition?
The change is very simple and should not require you to change your build target at all (assuming you are targeting Android 1.6 or above, of course). The key changes you must make are:
For each Activity that makes use of the support libraries, have it extend FragmentActivity instead.
In each FragmentActivity, replace all calls to getLoaderManager() with getSupportLoaderManager().
In each FragmentActivity, replace all calls to getFragmentManager() to getSupportFragmentManager().
Replace all relevant android.* imports with their corresponding support.v4.* import statements.