2

Possible Duplicate:
gesture issue with mapview in viewpager page

I use the template that allow us to swipe horizontally between tabs

But one of my tab is MapView, so when I swipe left/right in that MapView, it will switch tab instead of moving the map.

Is there any way to disable the gesture only in that MapView tab?

Thanks

Community
  • 1
  • 1
hrsetyono
  • 4,474
  • 13
  • 46
  • 80

1 Answers1

17

I found the answer from this question

In case the link is dead, I copied the code here:

Make a new class with this exact code, it will prevent MapView to receive any other gesture aside of map-related gesture. Don't forget to add your package and import (CTRL+SHIFT+O) above these code

public class CustomViewPager extends ViewPager {

    public CustomViewPager(Context context) {
        super(context);
    }

    public CustomViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
        if (v instanceof MapView) {
            return true;
        }
        return super.canScroll(v, checkV, dx, x, y);
    }
}

Then in main.xml change the <android.support.v4.view.ViewPager ... /> into this:

<com.yourPackage.CustomViewPager
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main" />

Thanks to Jorge Aguilar for the answer in that question!

Community
  • 1
  • 1
hrsetyono
  • 4,474
  • 13
  • 46
  • 80