Search code examples
androidseekbar

Android seekbar solution


Is it possible to have the seekbar move only when the thumb is moved. Right now the seekbar moves even on finger touch in the progressdrawable. How do we disable the movement of the seekbar on finger touch of the progressdrawable?

Thanks.


Solution

  • Override the OnTouchListener for the seekbar and only process the movement on the thumb when the MotionEvent is a move event.

    event.getAction() == MotionEvent.ACTION_MOVE

    Update : 1

    Something like this will work but the catch is that even if the user moves the thumb 2 units the seekbar moves. And you should really not stop this behavior as it would mess the the seekbar.

    seekBar.setOnTouchListener(new OnTouchListener() {
    
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if(event.getAction() == MotionEvent.ACTION_MOVE){
                        Log.d(TAG, "Moved , process data, Moved to :" + seekBar.getProgress());
                        seekBar.setProgress(seekBar.getProgress());
                        return false;
                    }
                    Log.d(TAG, "Touched , Progress :" + seekBar.getProgress());
                    return true;
                }
            });