HueSeekBar icon indicating copy to clipboard operation
HueSeekBar copied to clipboard

Focus easily lost within RecyclerViewAdapter

Open jeroenbeuz opened this issue 7 years ago • 2 comments

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 avatar Nov 09 '17 21:11 jeroenbeuz

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 avatar Nov 10 '17 11:11 jeroenbeuz

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;
                }
            });

jeroenbeuz avatar Nov 11 '17 10:11 jeroenbeuz