I have a switch
button (actually is a custom one) and I want to disable the swipe functionality for some reason; I want the user to be able to click it only. Is
A better way is to prevent the Switch class from receiving MotionEvent.ACTION_MOVE
events.
This can be done with:
switchButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return event.getActionMasked() == MotionEvent.ACTION_MOVE;
}
});
Then you are free to set a click listener on the switch as appropriate.
Check out the implementation of Switch to see how dragging works. It's pretty cool!