Switch button, disable change state onClick

bott picture bott · Jan 20, 2014 · Viewed 17.9k times · Source

I want to use a switch button but I want to disable the change status on click, let this change only to the drag option. I try to set onclick listener to do nothing but when I click on the button always change the state.

Some one know to disable the change status onClick?

Answer

HoseinIT picture HoseinIT · Jan 2, 2018

If you want to only change the state of the switch with swipe do the following:

 switchbutton = view.findViewById(R.id.switch2);
    switchbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchbutton.setChecked(!switchbutton.isChecked());
        }
    });