Step by Step _android Development Course [24]_ User interface checkbox (check box)

Source: Internet
Author: User

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

    • Subject: CheckBox for user interface (check box)
      -
      CheckBox check box (instance):
      Activity_main.xml:
<?xml version= "1.0" encoding= "Utf-8"?>  <linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  android:layout_width  =" fill_parent " android:layout_height  =" fill_parent " android:orientation  =;     <CheckBoxandroid:id= "@+id/beijing"android:layout_width="Wrap_ Content "android:layout_height=" Wrap_content "android:text="Beijing " />                        <CheckBoxandroid:id="@+id/shanghai"android:layout_width= "Wrap_content" android:layout_height="Wrap_content"android:text="Shanghai" />                       <CheckBoxandroid:id= "@+id/shenzhen"android:layout_width="Wrap_ Content "android:layout_height=" Wrap_content "android:text=" Shenzhen " />                        <TextViewandroid:id= "@+id/txt"android:layout_width=" Fill_parent "android:layout_height=" wrap_content " />               </linearlayout>  

Mainactivity.java:

Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.CheckBox;ImportAndroid.widget.CompoundButton;ImportAndroid.widget.TextView;ImportAndroid.widget.Toast; Public  class mainactivity extends Activity {CheckBox beijing=NULL; CheckBox shanghai=NULL; CheckBox shenzhen=NULL; TextView txt =NULL; Public void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);         Beijing= (CheckBox) Findviewbyid (r.id.beijing);         Shanghai= (CheckBox) Findviewbyid (R.id.shanghai);         Shenzhen= (CheckBox) Findviewbyid (R.id.shenzhen); txt= (TextView) Findviewbyid (r.id.txt);//compoundbutton is a button with a checked/unchecked state that automatically changes state when the button is pressed or clicked. Beijing.setoncheckedchangelistener (NewCompoundbutton.oncheckedchangelistener () {@Override             Public void oncheckedchanged(Compoundbutton Buttonview,BooleanisChecked) {//TODO auto-generated method stub                if(isChecked) {Txt.settext (Buttonview.gettext () +"Checked"); }Else{Txt.settext (Buttonview.gettext () +"Unchecked");        }            }        }); Shanghai.setoncheckedchangelistener (NewCompoundbutton.oncheckedchangelistener () {@Override              Public void oncheckedchanged(Compoundbutton Buttonview,BooleanisChecked) {//TODO auto-generated method stub                if(isChecked) {Txt.settext (Buttonview.gettext () +"Checked"); }Else{Txt.settext (Buttonview.gettext () +"Unchecked");         }             }         }); Shenzhen.setoncheckedchangelistener (NewCompoundbutton.oncheckedchangelistener () {@Override              Public void oncheckedchanged(Compoundbutton Buttonview,BooleanisChecked) {//TODO auto-generated method stub                if(isChecked) {Txt.settext (Buttonview.gettext () +"Checked"); }Else{Txt.settext (Buttonview.gettext () +"Unchecked");     }             }         }); }}

Operation Result:


Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

Step by Step _android Development Course [24]_ User interface checkbox (check box)

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.