Android Using only ViewPager from Support Library - android

The new edition of my app has a minimum SDK of 14, so I thought that I could get rid of the support.v4 library that I've been using for the older version. However, it now looks like I might have to use ViewPager and thus am back to including the library.
So can I just use the ViewPager-related classes from the library and not have to use the other classes that are now native in V14, such as Fragment (and also not have to change Activity to FragmentActivity)?
I would assume that I can do this (only use ViewPager from the library) but wanted to check to make sure.

You may have to use v13 support libraries for some things. If what you want to use exists in both v4 and v13, use v13. v13 works with Fragments native to the higher APIs, while v4 only works with v4 fragments.

I just created a project that has only ViewPager and it's closest dependencies - without Fragments and without actionbar, which are supported natively as of api level 14.
https://github.com/kilaka/ViewPager-Independent
Enjoy :)

Related

Why am i using support.v4 package when I am using Android v 17?

I think I'm missing something, but don't really understand the reasoning behind the support packages for objects like ViewPager and Fragment etc and how do I know which one to use?
I'm writing an app with min sdk 16, why are the objects not included somewhere in the API without the "support.v4" (some appear to be support v.13) qualification?
Can somebody shed a bit of light?
The support library is for the following reason:
for backwards compatibility
for functionality that is not included in the standard SDK's such as ViewPager
Here, ViewPager isn't included in the standard SDK. So, if you want to use Viewpager API then you have to use support library.
Fragment in the support library is mainly for backwards compatibility. If you are implementing something using support library which required to use Fragment then you will need to use Fragment from support library.

Why is ViewPager in android only available in the V4 Support library

I must be confused, I thought the V4 support library is supposed to help older devices to have newer API's, how come there is not equivalent ViewPager class if I do not use the V4 Support library?
The support library is not exclusively for compatibility with newer APIs. Some of the features (e.g. ViewPager, DrawerLayout, LocalBroadcastManager) are only present there.
As for "why", it's hard to say... I guess they wanted to make those widgets available independently of an Android release.

Where is getChildFragmentManager in support library v13?

Android support library v13 is supposed to provide support for newer APIs from Android 3.1. However, as far as I can tell there is no support for child fragments. Specifically, where is getChildFragmentManager()? The v13 support library relies on native fragments, which didn't add this method until API level 17. I have an app with minimum SDK level 14 so I should be able to use the v13 support library, but it seems I can't.
I don't want to go all the way back to the v4 support library and take on all it's weight. The v13 library is perfect otherwise.
If you want to use nested fragments within a native Fragment. use getFragmentManager().
If you want to use nested fragments within a support library Fragment, use getChildFragmentManager().
Just found this out by accident. It works. :)
Android support library v13 is supposed to provide support for newer APIs from Android 3.1
Not really.
However, as far as I can tell there is no support for child fragments
Correct. You cannot change existing classes from an external library in Java. android.app.Fragment already exists, therefore the library cannot add methods to Fragment.
I have an app with minimum SDK level 14 so I should be able to use the v13 support library, but it seems I can't.
You can simply not use nested fragments. Or, use the fragments backport.
I don't want to go all the way back to the v4 support library and take on all it's weight
android-support-v13.jar is larger than android-support-v4.jar.
If v13 included all of v4 then what is its purpose?
It adds some classes, like native-fragment implementations of FragmentPagerAdapter and FragmentStatePagerAdapter, that are not needed for apps who do not have native fragments, because their android:minSdkVersion is below 11.
the v13 library uses the native fragments and activities, not support fragment
android-support-v13.jar contains all of the android.support.v4 and all of the android.support.v13 classes from the SDK.
you should just use the v4 support library fragments. then you can use nested fragments w/ api 14. There is no real downside to doing so. They are already included in the v13 support library (it includes all of v4)

Nested Fragments with v13 of the Android Support Library

I am trying to use nested fragments with the v13 Android support library and I am unable to call getParentFragment(). I have use the v4 support library with nested fragments and have successfully made calls to getParentFragment.
Does the v13 Android support library support nested fragments? Or, can you only use nested fragments with the v4 support library, or if the app targets API 17?
Do not use v13 unless you know it's fine for you:
This library is designed to be used for Android 3.2 (API level 13) and
higher. It adds support for the Fragment user interface pattern with
the (FragmentCompat) class and additional fragment support classes For
more information about fragments, see the Fragments developer guide.
For detailed information about the v13 Support Library APIs, see the
android.support.v13 package in the API reference.
Use v4 of support library
I had this same issue. it turned out that my child fragment extended Fragment. I changed it to extend android.support.v4.app.Fragment and it worked fine.

Does the Android ICS API have a native equivalent to ViewPager support lib?

I have searched a bit around for a pager for fragment , I develop on ICS API.
I know about ViewPager and all the support libs for earlier version but i don't get why I should use a support library consider the fact that I use the lastest version of the api and don't plan to support earlier version.
Do I have to write the "ViewPager" myself or is there something i didn't see in the api.
Does the Android ICS API have a native equivalent to ViewPager support lib?
No.
I know about ViewPager and all the support libs for earlier version but i don't get why I should use a support library consider the fact that I use the lastest version of the api and don't plan to support earlier version.
The Android Support package is not only for backports of newer APIs. It is also for other classes that, for whatever reason, are not being added to the SDK, such as ViewPager and its supporting classes.
Do I have to write the "ViewPager" myself or is there something i didn't see in the api.
You are welcome to write your own implementation of a view paging component. Savvy programmers would use the one in the Android Support package, since it is already written and (mostly) debugged.
UPDATE: Note that ViewPager works just fine with pages that are:
API Level 11+ native fragments
Android Support backported fragments
arbitrary Views
For the first case, you need the v13 version of the support JAR, which contains v13 versions of the FragmentPagerAdapter and FragmentStatePagerAdapter classes.

Categories

Resources