第一步,还是创建android项目。

第二步,修改已经生成的res/layout/main.xml

 

view plain copy to clipboard print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. "http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6. >  
  7.     
  8.         android:id="@+id/checkBox"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:text="复选框1" />  
  12.     
  13.         android:id="@+id/checkBox1"  
  14.         android:layout_width="wrap_content"  
  15.         android:layout_height="wrap_content"  
  16.         android:text="复选框2" />  
  17.     
  18.         android:id="@+id/radioGroup"  
  19.         android:orientation="vertical"  
  20.         android:layout_width="fill_parent"  
  21.         android:layout_height="fill_parent">  
  22.         "@+id/radion1"  
  23.             android:layout_width="wrap_content" android:layout_height="wrap_content"  
  24.             android:text="北京" />  
  25.         "@+id/radion2"  
  26.             android:layout_width="wrap_content" android:layout_height="wrap_content"  
  27.             android:text="天津" />  
  28.         "@+id/radion3"  
  29.             android:layout_width="wrap_content" android:layout_height="wrap_content"  
  30.             android:text="上海" />  
  31.         "@+id/radion4"  
  32.             android:layout_width="wrap_content" android:layout_height="wrap_content"  
  33.             android:text="重庆" />  
  34.       
  35.   

 

第三步,添加主要代码

 

view plain copy to clipboard print ?
  1. import android.app.Activity;  
  2. import android.os.Bundle;  
  3. import android.widget.CheckBox;  
  4. import android.widget.CompoundButton;  
  5. import android.widget.RadioButton;  
  6. import android.widget.RadioGroup;  
  7. import android.widget.CompoundButton.OnCheckedChangeListener;  
  8.   
  9.   
  10. public class checkBox extends Activity implements OnCheckedChangeListener  {  
  11.     /** Called when the activity is first created. */  
  12.       
  13.       
  14.     RadioButton  r1 = null;  
  15.     RadioButton  r2 = null;  
  16.     RadioButton  r3 = null;  
  17.     RadioButton  r4 = null;  
  18.       
  19.     @Override  
  20.     public void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.         setContentView(R.layout.main);  
  23.           
  24.         CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox);   
  25.         CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);  
  26.         //获得单选按钮组  
  27.         RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radioGroup);  
  28.         //获得单选按钮  
  29.         r1 = (RadioButton )findViewById(R.id.radion1);  
  30.         r2 = (RadioButton )findViewById(R.id.radion2);  
  31.         r3 = (RadioButton )findViewById(R.id.radion3);  
  32.         r4 = (RadioButton )findViewById(R.id.radion4);  
  33.           
  34.         checkBox.setChecked(true);   
  35.           
  36.         r1.setClickable(true);  
  37.         //监听多选按钮  
  38.         checkBox.setOnCheckedChangeListener(this);  
  39.         checkBox1.setOnCheckedChangeListener(this);  
  40.         //监听单选按钮  
  41.         radioGroup.setOnCheckedChangeListener(mChangeRadio);  
  42.           
  43.     }  
  44. //参考

  45.   http://blog.csdn.net/applezhengxd/archive/2010/05/06/5563512.aspx

更多相关文章

  1. Android 标题栏添加返回按钮及响应
  2. android之按钮单击事件及监听器的实现方式
  3. Android中悬浮按钮的实现(记录)
  4. Android状态栏上添加按钮
  5. Android学习(一) 按钮的事件
  6. 在Unity中捕捉Android的常用按钮返回事件
  7. sencha touch中处理Android返回按钮事件
  8. 给Android的音量按钮添加监听事件
  9. 多个按钮左右相互挤压效果

随机推荐

  1. Android(安卓)使用XML自定义菜单
  2. Android(安卓)Matrix图像变换处理
  3. Android(安卓)apk动态加载机制的研究(二):资
  4. Android(安卓)手把手带你玩转自定义相机
  5. MMKV学习(三)Android使用
  6. Android数据持久化,你还不会?
  7. 魅族-魅蓝note无法链接adb解决办法
  8. Android中的消息通知(NotificationManager
  9. Android接入微信H5支付及与Js交互
  10. Android中如何取消listview的点击效果