We have spent half of it before we know what life is.
What's in this lecture: switch control
Example one:
Here is the Res/layout/activity_main.xml layout file:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " > <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content " android:layout_marginleft= "10DP" android:text= "WiFi settings" android:textsize= "20sp"/> <switch android:id= "@+id/open" android:layout_width= "wrap_content" android:layout_height= "wrap_content " android:layout_alignparentright=" true " android:layout_marginright=" 10DP " android:texton=" WiFi on " android:textoff=" WiFi off in "/></relativelayout>
here is the mainactivity main interface file:
public class Mainactivity extends Activity {private Switch open;protected void OnCreate (Bundle savedinstancestate) {Super . OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); open= (Switch) Findviewbyid (r.id.open); o Pen.setoncheckedchangelistener (New Oncheckedchangelistener () {public void oncheckedchanged (Compoundbutton Buttonview, Boolean isChecked) {if (isChecked) {Toast.maketext (mainactivity.this, "open WiFi", Toast.length_long). Show () ;} Else{toast.maketext (Mainactivity.this, "Off WiFi", Toast.length_long). Show ();}});}}
Take your time and enjoy it
User Interface View switch