Its very hard to describe my problem but I'll do my best <<
when I want to make a ViewPager in MainActivity , I go to xml then :
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewPager"
/>
then I make an Adapter
public class MyAdapter extends FragmentPagerAdapter
here , I need to import
android.support.v13.app.FragmentPagerAdapter;
the QUESTION is ;
is there any problem when I use v4 , v13 on one application
note : I add the v13 library and make it as (provided)
On one hand you can use both v4 and v13 support packages. Sometimes you have to.
For example android.support.v13.app.FragmentPagerAdapter and android.support.v4.app.FragmentPagerAdapter are similar but not identical : they don't use the same kind of fragments (native android.app.Fragment vs support android.support.v4.app.Fragment).
So if you want to use a ViewPager with native fragment you have to extend the v13 FragmentPagerAdapter and set it on the ViewPager (v4, there is only one). Of course this will only work on v13+ devices.
On the other hand you don't have to declare both library : the v13 support lib includes the v4, adding something like
compile "com.android.support:support-v13:23.1.1"
in your build.gradle gives you access to both v4 an v13 support classes.
By the way, see Fragment or Support Fragment for more details about native vs support fragments.
Edit: There shouldn't be a problem using both, just don't set it as provided. Use compile as the classes are not provided by the system.
Related
I have two modules, one have fragments with support.v4 library and another with app.fragment. I need to use both fragments in one viewpager. Is there a way to use both fragment types in same viewpager? Because module which built using app.fragment is google source code (huge one, if I would have to rewrite it).. Thanks in advance, any ideas helps.
How would I use android.app.Fragment; inside FragmentStatePagerAdapter
It only supports returning: android.support.v4.app.Fragment. An existing fragment I am using inherits from RxFragment which doesn't use the support library fragment.
You can't.
FragmentStatePagerAdapter and FragmentPagerAdapter are part of the support library, and only support the support Fragments.
If you really want to do this, you could copy the source for those classes and replace the support Fragment imports with framework Fragment imports.
You can use android.app.Fragment if you use android.support.v13.app.FragmentStatePagerAdapter from the v13 Support Library. See this answer from #brillenheini
I have developer the whole my project with
import android.app.FragmentManager;
import android.app.FragmentTransaction;
and using Tabs with ActionBar. Now i need to swipe between tabs. I have seen many examples even the sample project of Android, but all imports they used are with support.v4.app and hence they can use FragmentPagerAdapter. My min sdk is 14. Is there any way to use FragmentPagerAdapter in my project or any alternative for Viewpager. I have gone through some of related post like :
FragmentPagerAdapter Exists Only In Android.Support.V4.App (and not Android.App)
Problems with FragmentPagerAdapter
When i import android.support.v13.app.FragmentPagerAdapter., it couldn't be resolved.
You could copy the source code and make necessary changes to use the non-support versions of the classes referenced in FragmentPagerAdapter (like Fragment). It should be enough to just change the imports to the non-support versions of those classes.
Import the library android-sdk\extras\android\support\v13\android-support-v13.jar
There is everything you need.
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 am following the example here
http://developer.android.com/reference/android/app/TabActivity.html
creating tabs using fragments and in the tutorial it uses TabManager but on my version it says it cannot be resolved.
I am using minsdk set to 14 and targetsdk set to 15.
I don't wish to use the backward compatible support.
Any ideas which package it is in?
Eclipse doesn't provide me any help, only asks me to create the class TabManager.
Thanks in advance
TabManager is for the compatibility fragment tabs, not for the 3.0+ fragment tabs. That's why it can't be resolved.
The tutorial here shows how to create fragment tabs in 3.0+:
http://developer.android.com/reference/android/app/ActionBar.html#newTab()
Also, you don't have to inherit from FragmentActivity starting in Honeycomb unless you want backwards compatibility. You can just inherit from Activity and Fragment will be supported.