Switch Android catching Varialvel

Asked

Viewed 383 times

0

I have a Switch component and would like to get its status whether it’s on or off. When searching on the net the examples that I got didn’t work but one worked but it only takes the value when I change on/off because of the function setOnCheckedChangeListener

I’d like to know a way to get the value.

Delivery would be my Switch.

 Entrega.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(Entrega.isChecked()){
                StatusEntrega = "Receber na Mesa";
            }else{
                StatusEntrega = "Receber no Balcão";
            }
        }
    });
  • Avoid using uppercase variable names

  • Please mark your response as certain if it has helped you.

1 answer

2


Use the Entrega.isChecked(), that returns a boolean with the Switch value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.