Good afternoon, my question is quite simple but I can not find how to make this element work in Android Studio:
Switch activar;
Boolean switchState;
activar.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
switchState = activar.isChecked ();
switche();
}
});
private void switche(){
if(switchState==false){ Toast.makeText(getApplicationContext(),"Desactivado",Toast.LENGTH_SHORT).show();
btnaceptar.setEnabled(false); }
if(switchState==true){ Toast.makeText(getApplicationContext(),"Activado",Toast.LENGTH_SHORT).show();
btnaceptar.setEnabled(false);}
My code works correctly by "CLick" on the Switch element, however if you slide your finger on it to turn it on or off it does not change its status or execute the "switch ()" class, and I understand that it is because I have it with a "setOnClickListener" but, How should I change it to detect if it slides with my finger instead of being clicked?
Thank you in advance.