Showing posts with label How to trigger onClickListener for HorizontalScrollView?. Show all posts
Showing posts with label How to trigger onClickListener for HorizontalScrollView?. Show all posts

Wednesday, 10 June 2015

How to trigger onClickListener for HorizontalScrollView?


Method 1 :

 HorizontalScrollView scrollView = (HorizontalScrollView) findViewById(R.id.scrollView);

    final GestureDetector detector = new GestureDetector(this, new OnGestureListener() {

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            // Do stuff.
            return false;
        }

        // Note that there are more methods which will appear here 
        // (which you probably don't need).
    });


    scrollView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            detector.onTouchEvent(event);
            return false;
        }
    });

Method 2 :


HorizontalScrollView scrollView = (HorizontalScrollView) findViewById(R.id.scrollView);

    scrollView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                // Do stuff
            }
            return false;
        }
    });