Search code examples
androidtogglebutton

How to permanently disable toggle button?


First I want to change the state of toggle button from false to true, then if its true I want to disable toggle button so no one can change it again.Please help me as I am new to android.


Solution

  • You may do like this,

        //get the button as
        ToggleButton tb =  (ToggleButton) findViewById(R.id.togglebutton1);
        // check it is enabled
        if(tb.isChecked()){
            //do something on enabling it
            tb.setEnabled(false);  // disable it
        }