7

I am trying to implement vertical swiping in my app. (Its just like the swiping with ViewPager, but vertically).

I found Jake Whartons library Android-DirectionalViewPager. It is a standalone .jar file which should be included in addition to the compatibility library. I included the file in my project. It is now under 'Referenced Libraries', just like the compatibility library.
But the problem is, I cant even get the example, which is given with the library, to work. The debugger stops at line

setContentView(R.layout.main);

with 'No source found'

LogCat throws this error: "05-23 14:43:13.583: E/dalvikvm(329): Could not find class 'com.directionalviewpager.DirectionalViewPager', referenced from method own.vvp.MainActivity.onCreate "

Has somebody already used this library? I need some help :)

here is my code:

the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="own.vvp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

the layout:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.directionalviewpager.DirectionalViewPager
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="2dp"
    android:orientation="horizontal">

    <Button
        android:id="@+id/horizontal"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginRight="1dp"
        android:text="Horizontal" />
    <Button
        android:id="@+id/vertical"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginLeft="1dp"
        android:text="Vertical" />

</LinearLayout>

</LinearLayout>

and the main activity:

package own.vvp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import com.directionalviewpager.DirectionalViewPager;


public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Set up the pager
    final DirectionalViewPager pager = (DirectionalViewPager)findViewById(R.id.pager);
    pager.setAdapter(new TestFragmentAdapter(getSupportFragmentManager()));

    //Bind to control buttons
    ((Button)findViewById(R.id.horizontal)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setOrientation(DirectionalViewPager.HORIZONTAL);
        }
    });
    ((Button)findViewById(R.id.vertical)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setOrientation(DirectionalViewPager.VERTICAL);
        }
    });
}
}

it is the same code as in the example, except for the package name and the name of the main activity, so I guess, the way I included the library must be wrong.

Thanks!

kiberNet
  • 155
  • 1
  • 7

3 Answers3

19

Update (Feb 1st 14): This library is a really good alternative. I'm currently using it in my project and it's working flawlessly. It's still being maintained and it's a very close modification of the standard ViewPager from support lib r19. Another advantage is, that you can easily integrate and resolve it via maven central, if you're using gradle.

https://github.com/castorflex/VerticalViewPager


Thanks to Oleg Vaskevich, I was able to compile a new and working directionalViewpager jar-file from the current git files and oleg's additions/fixes. I can confirm that it's working with the current support-lib v4 r11.

https://dl.dropbox.com/u/24363935/android-directionalviewpager-1.2.1fixed.jar

hopefully this will be useful to somebody :)

to add: I had an IllegalArgumentException in DirectionalViewPager.setAdapter(PagerAdapter adapter){...};. So I've modified and fixed, recompiled and uploaded the new jar.

MrMaffen
  • 1,647
  • 1
  • 17
  • 22
  • Hi, great job! However, it gives me error when including it in a layout, it says: (next comment) – vitakot Jan 13 '13 at 17:45
  • The following classes could not be instantiated: - android.support.v4.view.DirectionalViewPager. 01-13 18:45:43.590: E/AndroidRuntime(4875): android.view.InflateException: Binary XML file line #15: Error inflating class fragment, java.lang.IllegalAccessError: tried to access method android.support.v4.view.ViewPager.initViewPager()V from class android.support.v4.view.DirectionalViewPager at android.support.v4.view.DirectionalViewPager.initViewPager(DirectionalViewPager.java:136) at android.support.v4.view.DirectionalViewPager.(DirectionalViewPager.java:123). **Any ideas?** – vitakot Jan 13 '13 at 17:46
  • Sounds like the JAR wasn't properly packed? See [this question](http://stackoverflow.com/a/7076502/832776). – Oleg Vaskevich Jan 13 '13 at 19:14
  • I'm using android-support-v4.jar revision 11. I'm compiling with java version 1.7.0_10. Please confirm that you are using the same setup. I'm currently using this exact .jar file within my project and I don't get any errors. Hope you can get it sorted out :) – MrMaffen Jan 13 '13 at 21:46
  • Hey, I can't get it to work, I get a NullpointerException at launch android.support.v4.view.ViewPager.getChildDrawingOrder with the jar, if I add the code from Oleg i get a duplicate dex, dalvik cant be built and the app doesnt even compile.. can you help me? – A. Steenbergen Feb 22 '13 at 15:17
  • 1
    I fixed it, appearantly you cannot use setPageTransformer(true, new ZoomOutPageTransformer()); in the DirectionalViewpager... – A. Steenbergen Feb 22 '13 at 15:37
  • 1
    is there a way to fixe this? I think I am not experienced enough in Android for this – A. Steenbergen Feb 22 '13 at 15:45
  • java.lang.NoSuchMethodError: android.support.v4.view.PagerAdapter.registerDataSetObserver – sheetal Mar 01 '13 at 09:26
  • got it..my v4 lib was not 11 – sheetal Mar 01 '13 at 10:36
  • any chance of getting Page Transformers to work in the Directional ViewPager? Is it very difficult to fix? – rupps May 07 '13 at 14:56
  • More insight into PageTransformers: populate() in ViewPager at the end fills up a LUT "private ArrayList mDrawingOrderedChildren;" with child drawing order, this is the one that gives a null pointer exception because populate in DVP totally overrides the one in VP and the LUT is never initialized... The problem is, being private in ViewPager, we have to modify the ViewPager source, split out this part from populate, then manually call it from DVP's populate... any volunteers? :P – rupps May 07 '13 at 15:18
  • Thanks for this fix. However, this viewpager does not support correctly the method setOffscreenPageLimit(int i) - the method seems to be ignored. Any idea why ? – Sébastien BATEZAT Jun 22 '13 at 13:26
  • It could be that `ViewPager` was updated in the later support libraries, and is now incompatible with `DirectionalViewPager`, which is deprecated for a reason. – Oleg Vaskevich Jun 28 '13 at 13:39
  • 1
    if you get this error `java.lang.IllegalStateException: Recursive entry to executePendingTransactions` use `getChildFragmentManager()` :) – yashhy Jun 09 '14 at 16:04
14

DVP is deprecated by the developer due to significant changes to ViewPager since. However, that doesn't mean there is no use for it.

Try downloading the source directly and including the two source files within your project. If you're using the latest support/compatibility library you will need to use android.database.DataSetObserver instead of ViewPager.DataSetObserver. Hope this helps!

Modified code that should work: https://dl.dropbox.com/u/21007282/Code/DirectionalViewPager-works.zip

Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80
0

I was facing many issues when integrating the old Jake Wharton project which was archived. I came along this github project and it was properly integrating with the newest app compat/support version. Hope it helps someone. Vertical as well as horizontal view pager swipe

Ravi Yadav
  • 2,296
  • 3
  • 25
  • 32