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
//This code works fine
public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener { Switch my_switch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
my_switch = (Switch) findViewById(R.id.my_switch);
my_switch.setOnCheckedChangeListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.my_switch:
if(my_switch.isChecked())
my_switch.setChecked(true);
else
my_switch.setChecked(true);
break;
}
}
}