Search code examples
androidontouchlistenerseekbar

Get SeekBar touch position (without progress change)


I have a simple discrete SeekBar indicating a progression from 0 to 10.

The progression of the SeekBar is defined programmatically, so I disabled touch events in order to prevent the user from changing its current position:

mSeekBar.setOnTouchListener(new View.OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            return true;
        }
    });

However, I need to get the position the user touched on the SeekBar (regardless of its current progress).

Basically, if the user touches the first "dot", he goes to one activity, if he touches the second, he goes to another, etc... But none of these actions should change the current state of the SeekBar.

How can I achieve that?


Solution

  • I didn't find any way to achieve what I wanted to, so I had to find a small workaround.

    I just added a second, invisible SeekBar on top of the other one, used only to handle touch events using onSeekBarChangedListener.

    To make it transparent, I used:

    android:progressDrawable="@android:color/transparent"
    

    The other SeekBar is used as before, only to display progress information. That way I have to separate behaviors.