iammert / HueSeekBar

Yet another android seekbar inspired from Philips Hue app
110 stars 27 forks source link

Focus easily lost within RecyclerViewAdapter #4

Open jeroenbeuz opened 7 years ago

jeroenbeuz commented 7 years ago

When the HueSeekBar is placed in a RecyclerViewAdapter, changing the seekbar by dragging it easily loses it's focus. In the testapp the focus is kept when you keep your finger inside the RelativeLayout view. Within an adapter the focus is lost on the slightest vertical movement.

jeroenbeuz commented 7 years ago

Also happens when you include all the seekbars in your testapp inside an ScrollView. The slightest vertical movement results in focus loss. So it's not RecyclerViewAdapter related.

jeroenbeuz commented 7 years ago

Solved by setting an ontouchlistener:

 recyclerViewHolder.seekbar.setOnTouchListener(new View.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 Seekbar touch events.
                    v.onTouchEvent(event);
                    return true;
                }
            });