0

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)

maysara
  • 5,873
  • 2
  • 23
  • 34
  • why would you use it ? – Blackbelt Dec 29 '15 at 10:47
  • you can use android support design library. It's very usefu and easy to implement. – oalpayli Dec 29 '15 at 10:58
  • Answer to your question: Granted you meet the minimum SDK requirement for both (i.e. minSDK="16" for example), there should be no problem with using both in the same application (most people end up using 4 and 7). However, `FragmentPagerAdapter` also exists in support v4: http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html so you shouldn't need to import v13 just for that. – kha Dec 29 '15 at 11:07

2 Answers2

1

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.

tknell
  • 9,007
  • 3
  • 24
  • 28
  • and how do you explain that there is no ViewPager in v13 but there in the Adapter for it? – Blackbelt Dec 29 '15 at 10:53
  • Okay, I take back what I said :) I misread the documentation. – tknell Dec 29 '15 at 10:59
  • can u see my pervious question , please , it will explain alot Really this bug blow up my mind !! I see a lecture video for a teacher and he use multiple libraries !!! – maysara Dec 29 '15 at 11:00
  • I made an edit, maybe that will also fix the problem from your previous question. – tknell Dec 29 '15 at 11:05
  • bro >>>> i have a new bug Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 2 – maysara Dec 29 '15 at 11:09
  • Is there any other error or warning output above the exception? – tknell Dec 29 '15 at 11:10
  • Maybe try clean the project and build it again. – tknell Dec 29 '15 at 11:26
1

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.

bwt
  • 17,292
  • 1
  • 42
  • 60