Android Radio (radiogroup) Check (checkbox) button app

Source: Internet
Author: User
The first step is to create an Android project.

The second step is to modify the generated Res/layout/main.xml

View Plaincopy to Clipboardprint?

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

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

android:orientation= "Vertical"

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

>

<checkbox

Android:id= "@+id/checkbox"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "check box 1"/>

<checkbox

Android:id= "@+id/checkbox1"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "check box 2"/>

<radiogroup

Android:id= "@+id/radiogroup"

android:orientation= "Vertical"

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent" >

<radiobutton android:id= "@+id/radion1"

Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"

android:text= "Beijing"/>

<radiobutton android:id= "@+id/radion2"

Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"

android:text= "Tianjin"/>

<radiobutton android:id= "@+id/radion3"

Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"

android:text= "Shanghai"/>

<radiobutton android:id= "@+id/radion4"

Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"

android:text= "Chongqing"/>

</RadioGroup>

</LinearLayout>

Step three, add the main code

View Plaincopy to Clipboardprint?

Import android.app.Activity;

Import Android.os.Bundle;

Import Android.widget.CheckBox;

Import Android.widget.CompoundButton;

Import Android.widget.RadioButton;

Import Android.widget.RadioGroup;

Import Android.widget.CompoundButton.OnCheckedChangeListener;

public class CheckBox extends Activity implements Oncheckedchangelistener {

/** called when the activity is first created. */

RadioButton r1 = null;

RadioButton r2 = null;

RadioButton r3 = null;

RadioButton r4 = null;

@Override

public void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.main);

CheckBox checkbox = (checkbox) Findviewbyid (R.id.checkbox);

CheckBox checkBox1 = (checkbox) Findviewbyid (R.id.checkbox1);

Get a radio button group

Radiogroup Radiogroup = (radiogroup) Findviewbyid (R.id.radiogroup);

Get radio button

R1 = (RadioButton) Findviewbyid (R.id.radion1);

r2 = (RadioButton) Findviewbyid (R.id.radion2);

R3 = (RadioButton) Findviewbyid (R.id.radion3);

R4 = (RadioButton) Findviewbyid (R.ID.RADION4);

Checkbox.setchecked (TRUE);

R1.setclickable (TRUE);

Monitor Multi-Select button

Checkbox.setoncheckedchangelistener (this);

Checkbox1.setoncheckedchangelistener (this);

Listen radio button

Radiogroup.setoncheckedchangelistener (Mchangeradio);

}

  • Related Article

    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.