<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <RadioGroup        android:id="@+id/radiogroup"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <RadioButton            android:id="@+id/radioman"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:checked="true"            android:text="男" />        <RadioButton            android:id="@+id/radiowoman"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="女" />        <RadioButton            android:id="@+id/radionoman"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="非人类" />    </RadioGroup>    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <CheckBox            android:id="@+id/checkandroid"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="android" />        <CheckBox            android:id="@+id/checknet"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text=".net" />        <CheckBox            android:id="@+id/checkjava"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="java" />    </LinearLayout>    <ToggleButton        android:id="@+id/tbtn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textOff="开"        android:textOn="关" /></LinearLayout>
 1 package com.example.classtest; 2  3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.widget.CheckBox; 6 import android.widget.CompoundButton; 7 import android.widget.RadioButton; 8 import android.widget.RadioGroup; 9 import android.widget.RadioGroup.OnCheckedChangeListener;10 import android.widget.Toast;11 import android.widget.ToggleButton;12 13 14 public class MainActivity extends Activity implements15         CompoundButton.OnCheckedChangeListener {16 17     @Override18     protected void onCreate(Bundle savedInstanceState) {19         super.onCreate(savedInstanceState);20         setContentView(R.layout.checktest);21         RadioGroup group = (RadioGroup) findViewById(R.id.radiogroup);22         group.setOnCheckedChangeListener(new OnCheckedChangeListener() {23 24             @Override25             public void onCheckedChanged(RadioGroup arg0, int arg1) {26 27                 RadioButton button = (RadioButton) findViewById(arg1);28                 Toast.makeText(MainActivity.this, button.getText(),29                         Toast.LENGTH_SHORT).show();30             }31         });32 33         CheckBox chkjava = (CheckBox) findViewById(R.id.checkjava);34         CheckBox chknet = (CheckBox) findViewById(R.id.checknet);35         CheckBox chkandroidBox = (CheckBox) findViewById(R.id.checkandroid);36         chkandroidBox.setOnCheckedChangeListener(this);37         chkjava.setOnCheckedChangeListener(this);38         chknet.setOnCheckedChangeListener(this);39 40         ToggleButton toggleButton = (ToggleButton) findViewById(R.id.tbtn);41         toggleButton.setOnCheckedChangeListener(this);42     }43 44     @Override45     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {46         // TODO Auto-generated method stub47         Toast.makeText(MainActivity.this,48                 buttonView.getText().toString() + isChecked, Toast.LENGTH_SHORT)49                 .show();50     }51 }

ANDROID笔记:CheckBox的简单使用

更多相关文章

  1. Android笔记:Activity的生命周期(图)
  2. ANDROID笔记:自定义CheckBox样式
  3. Android菜鸟的成长笔记(20)——IntentService
  4. 【Android自学笔记】Android获取手机和存储卡上的图片
  5. android各种对话框总结笔记
  6. 【Android笔记】Activity涉及界面全屏的方法
  7. Andorid访问WebService的学习笔记
  8. Android NDK学习笔记15-配置AndroidStudio
  9. Android 学习笔记(十四):Activity-AutoCompleteTextView

随机推荐

  1. 测试经理教你如何用monkey进行压力测试!
  2. android adb pull/push permission denie
  3. Android(安卓)ListView的优化
  4. [转]android out of memory(OOM)
  5. Android基于XMPP的即时通讯
  6. Android中利用Camera与Matrix实现3D效果
  7. android Java代码设置textview的字体资源
  8. 【Android开发bug】Dropping event due t
  9. Google Map Android API V1中API Key的生
  10. android input设备event处理以及hotplug