I am coding my xml file with the couple switch widgets. but I don't know how to set the default value of them as ON. And I just want to get this problem solved within the xml file so no Java.
-
what exactly "switch widget" mean to you?– Marcin OrlowskiSep 3, 2012 at 14:46
-
1@WebnetMobile.com developer.android.com/reference/android/widget/Switch.html - new in ICS - Screenshot here– user658042Sep 3, 2012 at 14:49
-
2please accept the answer if this helped. It helpful for future users.– RanjithkumarJun 29, 2016 at 1:04
Add a comment
|
3 Answers
To make Switch set "ON" in you XML file use this:
android:checked="true"
To set the Switch default as ON in XML file :
android:checked = "true"
Don't try using android:pressed = "true" . It will throw an error while running the app.
You can set the Switch default as ON/OFF from the code itself. Try something like this:
switch.setChecked(true) // to set it true
Or,
switch.setChecked(false) // to set it false