How to use Toggle Button in Android from the best Training Institute
Create an Android Application name as ToggleButtonDemo.
Open activity_main.xml insert the each one Toggle Button and Button name as Submit.
After that come into MainActivity.java page. Create a global object for toggle and submit button.
And inside the onCreate method connect with the widget function to the java page like follow
then set the onClickListener for the submit button for when user click the submit button do some action behind the code on this event.
Next create a StringBuilder class and its object used to get the values whether the toggle button is on or off status.
StringBuilder result = new StringBuilder();
Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
The string object “result” get the status of toggle button that will display using Toast widget. Then Click the run button or right click the project from project explore -> run as -> Android Application. The result will display in emulator.
Emulator shows the default first page of app like this.
After the click button when toggle is off the Toast result will display “ToggleButton: OFF” then click the Toggle button it will turn on then click again the click button result like “ToggleButton: ON”.
Thank you. This Android Application App designed & created by the XPLORE IT CORP Coimbatore.