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.
Related
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 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 :)
If I do not need to grant support for older versions of android and can just use API 17, is there an alternative way to implement the much advertised horizontal swipe (like in gmail) and not use viewpager, fragmentsactivities (new APIs already have fragments...) etc. to get rid of the support library?
All the tutorials I've found for horizontal swipe show how to do it using the support library and FragmentActivities. Otherwise what is the advantage of the new APIs if I cannot use their native classes and methods?
to get rid of the support library
ViewPager only exists in the Android Support Library. The Android Support Library is not just for backports.
new APIs already have fragments
ViewPager can use native API Level 11 fragments, though you may need to create your own PagerAdapter. Or, you can use ViewPager without any fragments, using just ordinary View or ViewGroup objects for the pages.
is there an alternative way to implement the much advertised horizontal swipe
You are welcome to write your own replacement for ViewPager. Most developers prefer to reuse ViewPager, for reduced development and maintenance costs.
There is also HorizontalScrollView, an open source HorizontalListView floating around, and so on.
You can write your own FragmentPagerAdapter which works with android.app.Fragment instead of android.support.v4.app.Fragment to minimize dependency on the support library. You only need to create your own class for the adapter (based on FragmentPagerAdapter from support library which source can be found in folder <android-sdks>/extras/android/support/v4/src/java/android/support/v4/app/). Only modification is in the import section - you should reference Fragment, FragmentManager and FragmentTransaction from android.app instead of android.support.v4.app.
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.