Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android seekbar how to block dragging / disable it for short time

I want to block the dragging of a seekbar if a value is true. Is this even possible? I use a seekbar as a switch. If my seekbar value is 0, and I press the button action A started. If my seekbar value is 1 and I press the button action B is started.
I want to prevent that If action A or B is running the seekbar is dragged to another position.

How can I achieve this?

like image 943
Leandros Avatar asked Sep 10 '25 14:09

Leandros


2 Answers

You should set your own onTouchListener and just return true.

seekBar.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return true;
            }
        });
like image 168
Maxim Tulupov Avatar answered Sep 12 '25 05:09

Maxim Tulupov


Have you tried disabling the view?

Ref: http://developer.android.com/reference/android/view/View.html#setEnabled(boolean)

Update:

https://stackoverflow.com/a/3278616/529691

Ideally you shouldn't be doing this, as this is going to confuse the user. My suggestion is rethink your approach.

like image 39
JoxTraex Avatar answered Sep 12 '25 04:09

JoxTraex