Error including Android-DirectionalViewPager .jar in Eclipse
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!
Solution 1:
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.
Solution 2:
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