Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable the gestures in PagerAdapter/ViewPager

first of all sorry for my bad english.

I got a working PagerAdapter with 3 Views. It works fine. I can switch through the Views with normal gestures AND with Buttonclicks. But i want to disable the gestures. Is it possible to switch through the Views only with buttonClicks and disable the gestures?

here is the PagerAdapter:

public class MyPagerAdapter extends PagerAdapter {


        public int getCount() {
            return 3;
        }

        public Object instantiateItem(View collection, int position) {

            LayoutInflater inflater = (LayoutInflater) collection.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            int resId = 0;
            switch (position) {
            case 0:
                resId = R.layout.back;
                break;
            case 1:
                resId = R.layout.stock;
                break;
            case 2:
                resId = R.layout.menu;
                break;
            }

            View view = inflater.inflate(resId, null);

            ((ViewPager) collection).addView(view, 0);

            return view;
        }

        @Override
        public void destroyItem(View arg0, int arg1, Object arg2) {
            ((ViewPager) arg0).removeView((View) arg2); 

        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == ((View) arg1);

        }

        @Override
        public Parcelable saveState() {
            return null;
        }
    }

SOLVED:

    final View touchView = findViewById(R.id.remotePager);
    touchView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            return true;
        }
    });
like image 240
user1453317 Avatar asked Jun 13 '12 09:06

user1453317


1 Answers

Override the onTouchListener() and return false to disable paging on swipe.

public boolean onTouchEvent(android.view.MotionEvent ev) {
        if (super.onTouchEvent(ev)) {
            return false;
        }
}
like image 171
O__O Avatar answered Oct 22 '22 13:10

O__O