ananddasani / Android_Toggle_Button_And_Switch

Using Toggle Button and Switch in Android App

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android_Toggle_Button_And_Switch

Using Toggle Button and Switch in Android App

This topic is a part of My Complete Andorid Course

Code

1st Activity

ToggleButton toggleButton;
Switch aSwitch;

toggleButton = findViewById(R.id.toggleButton);
aSwitch = findViewById(R.id.switch1);

          toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                    Toast.makeText(getApplicationContext(), "Checked", Toast.LENGTH_SHORT).show();
                else
                    Toast.makeText(getApplicationContext(), "Unchecked", Toast.LENGTH_SHORT).show();
            }
        });

        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                    Toast.makeText(getApplicationContext(), "Switch Checked", Toast.LENGTH_SHORT).show();
                else
                    Toast.makeText(getApplicationContext(), "Switch Unchecked", Toast.LENGTH_SHORT).show();
            }
        });

App Highlight

Toggle Switch App1 Toggle Switch App2 Toggle Switch App3 Toggle Switch Code

About

Using Toggle Button and Switch in Android App

License:MIT License


Languages

Language:Java 100.0%