Example on ToggleButton

后端 未结 7 1293
悲哀的现实
悲哀的现实 2021-01-12 07:08

I am developing an application using a toggle button, I entered 1 or 0 in EditText. When button is clicked, the toggle button has to change if I enter 1 the tog

7条回答
  •  囚心锁ツ
    2021-01-12 07:24

    You should follow the Google guide;

    ToggleButton toggle = (ToggleButton) findViewById(R.id.togglebutton);
    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // The toggle is enabled
            } else {
                // The toggle is disabled
            }
        }
    });
    

    You can check the documentation here

提交回复
热议问题