Android Basic three checkbox

Source: Internet
Author: User

Activity_main.xml
<linearlayout 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 "Tools:context = "Com.vincentlin.checkbox.MainActivity" > <checkbox android:id= "@+id/checkbox1" Android:layout_widt H= "Wrap_content" android:layout_height= "wrap_content" android:text= "@string/basketball"/></linearlayo Ut>
Strings.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>

<string name= "App_name" >CheckBox</string>
<string name= "Hello_world" >hello world!</string>
<string name= "Action_settings" >Settings</string>
<string name= "basketball" > Basketball </string>

</resources>

Mainactivity.java
Package com.vincentlin.checkbox;import android.app.activity;import android.os.bundle;import  android.util.Log;import android.view.Menu;import android.view.MenuItem;import  android.widget.checkbox;import android.widget.compoundbutton;import  android.widget.compoundbutton.oncheckedchangelistener;public class mainactivity extends  activity { private checkbox checkbox;  @Override  protected void  OnCreate (bundle savedinstancestate)  {  super.oncreate (savedinstancestate);   Setcontentview (r.layout.activity_main);   //Initialize checkbox  checkbox =  (checkbox)  findviewbyid (r.id.checkbox1)   //the checkbox is selected by setting the Listener event for the checkbox    Checkbox.setoncheckedchangelistener (New oncheckedchangelistener ()  {        @Override    public void oncheckedchanged (compoundbutton buttonview, boolean ischecked)  {    //to listen for the current checkbox is selected by oncheckedchanged &NBSP;&NBSP;&NBSP;&NBSP;LOG.I ("tag",  ischecked+ "");    if  (isChecked)  {      //get the text content of a checkbox      String text =  Checkbox.gettext (). toString (); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;LOG.I ("tag",  text);     }     }  });  }}

Android Basic three checkbox

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.