Android Switch picking up Varialvel

0

I have a Switch component and would like to get its status if it is on or off. When searching the net for the examples I got it did not work but it worked fine but it only takes the value when I make the on / off change because of the setOnCheckedChangeListener

I would 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";
            }
        }
    });
    
asked by anonymous 18.10.2017 / 16:02

1 answer

2

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

    
18.10.2017 / 17:52