Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Pass gesture event to another view

I am continuing work on my Sticky ListView, in which a specified view in a ListView will stick to the top and/or bottom as it passes by. I've accomplished this by setting up a View that is identical to the list item, and showing or hiding it as the list item passes on and off the screen.

My problem is, that when these 'sticky' items are present, I want them to react to touch as if they are part of the listview itself. For example, a fling down on the top sticky should send the listview scrolling down.

My question is if it's possible to assign an touch listener to this view, and then pass these events directly to the list.

I was hoping it would be as easy as:

ListView list;

....

stickyview.setOnTouchListener(new OnTouchListener() {


        @Override
        public boolean onTouch(View arg0, MotionEvent motionEvent) {
            list.onTouchEvent(motionEvent);
            return false;
        }

    });
like image 697
Josh Avatar asked Nov 18 '12 13:11

Josh


2 Answers

I got it with some slight tweaking:

stickyView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return list.onTouchEvent(event);
        }
    });
like image 167
Josh Avatar answered Oct 14 '22 01:10

Josh


I had to use dispatchTouchEvent(MotionEvent event) to achieve this in my situation

like image 1
hmac Avatar answered Oct 14 '22 02:10

hmac