Android 8th Lesson-switching ToggleButton, switch

Source: Internet
Author: User

Today we are listening to switches, two switches, ToggleButton and switch.

<LinearLayoutxmlns: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"android:orientation= "vertical"><ToggleButtonAndroid:id= "@+id/togglebutton"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:texton= "vertical arrangement"Android:textoff= "Horizontal arrangement"android:checked= "true" /><SwitchAndroid:id= "@+id/switcher"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:texton= "vertical arrangement"Android:textoff= "Horizontal arrangement"android:checked= "true"/>
<LinearLayoutAndroid:id= "@+id/test"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Test button One" /> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Test button two" /> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Test button three" /> </LinearLayout></LinearLayout>

The switch controls whether the three buttons are horizontal or vertical, so you need to wrap the three buttons together and use a linear layout as a whole. One does not understand is why to use android:checked= "true"? Is the meaning of whether to be selected ...

 PackageCom.example.togglebutton;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.CompoundButton;ImportAndroid.widget.CompoundButton.OnCheckedChangeListener;Importandroid.widget.LinearLayout;ImportAndroid.widget.Switch;ImportAndroid.widget.ToggleButton; Public classMainactivityextendsActivity {ToggleButton ToggleButton;    Switch switcher; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); ToggleButton=(ToggleButton) Findviewbyid (R.id.togglebutton); Switcher=(Switch) Findviewbyid (R.id.switcher); FinalLinearLayout test=(LinearLayout) Findviewbyid (r.id.test); Oncheckedchangelistener Listener=NewOncheckedchangelistener () {@Override Public voidoncheckedchanged (Compoundbutton Buttonview,BooleanisChecked) {            //TODO auto-generated Method Stub            if(isChecked) {test.setorientation (1);//Vertical}Else{test.setorientation (0);//level            }        }    };    Togglebutton.setoncheckedchangelistener (listener);    Switcher.setoncheckedchangelistener (listener); }}

This inside let me realize a focus is data field, and ordinary variable ...

Why use ToggleButton and swithcer as data fields? Why is the test not used as part of the data field?

And one of the reasons why test is final?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.