Use of Switch widget in android studio

program is-

public class MainActivity extends AppCompatActivity {
    EditText e;
    Switch s;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        e = (EditText) findViewById(R.id.editText);
        s = (Switch) findViewById(R.id.switch1);
    }

    public void perform (View view) {
        boolean b=s.isChecked();
         e.setText("" + b);
    }
}

Leave a Reply