ISchwarz23 / SortableTableView

An Android library containing a simple TableView and an advanced SortableTableView providing a lot of customisation possibilities to fit all needs.
Apache License 2.0
1.05k stars 239 forks source link

TableView OnTouchListener #143

Open torexko opened 6 years ago

torexko commented 6 years ago

Hi, I have a problem with the TableView. Setting a new OnTouchListener with .setOnTouchListener() doesn't seem to work properly. The overridden method onTouch never gets called. What am I missing? Is that an intended behavior? How can I register touch events on the TableView? Thank you.

ISchwarz23 commented 6 years ago

Hi @torexko,

it was not intended to use the OnTouchListener at all. What are you trying to achieve? Why do you need to listen for OnTouchEvents?

Best regards, Ingo

torexko commented 6 years ago

Because there is another View interfering with touch events and I can't scroll the TableView. I had the same problem with a ListView inside a ScrollView and I was able to make it work using this piece of code:

        listView.setOnTouchListener(new ListView.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        // Disallow ScrollView to intercept touch events.
                        v.getParent().requestDisallowInterceptTouchEvent(true);
                        break;

                    case MotionEvent.ACTION_UP:
                        // Allow ScrollView to intercept touch events.
                        v.getParent().requestDisallowInterceptTouchEvent(false);
                        break;
                }

                // Handle ListView touch events.
                v.onTouchEvent(event);
                return true;
            }
        });