android radiobutton和checkbox的使用
2014-02-10 16:14
295 查看
package com.studymar.radiocheckbox; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.RadioButton; import android.widget.RadioGroup; public class RadioCheck extends Activity { //1.声明控件 RadioGroup radioGroup=null; RadioButton radioButton1=null; RadioButton radioButton2=null; CheckBox checkBox1=null; CheckBox checkBox2=null; CheckBox checkBox3=null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //2.控件赋值 setvalue(); //3.控件监听 setlistener(); } private void setlistener() { radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(radioButton1.getId()==checkedId){ Log.i("123", "radioButton1 is checked"); }else if(radioButton2.getId()==checkedId){ Log.i("123", "radioButton2 is checked"); }else{ Log.i("123", "no radiobutton is checked"); } } }); checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked==true){ Log.i("123", "check1 is checked"); }else{ Log.i("123", "check1 is not checked"); } } }); checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked==true){ Log.i("123", "check2 is checked"); }else{ Log.i("123", "check2 is not checked"); } } }); checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked==true){ Log.i("123", "check3 is checked"); }else{ Log.i("123", "check3 is not checked"); } } }); } private void setvalue() { radioGroup=(RadioGroup)findViewById(R.id.rdgroup); radioButton1=(RadioButton)findViewById(R.id.radioone); radioButton2=(RadioButton)findViewById(R.id.radiotwo); checkBox1=(CheckBox)findViewById(R.id.checkone); checkBox2=(CheckBox)findViewById(R.id.checktwo); checkBox3=(CheckBox)findViewById(R.id.checkthree); } }
<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" android:orientation="vertical" tools:context=".MainActivity" > <RadioGroup android:id="@+id/rdgroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/radioone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/radio1" android:layout_weight="1" /> <RadioButton android:id="@+id/radiotwo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/radio2" android:layout_weight="1" /> </RadioGroup> <CheckBox android:id="@+id/checkone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/check1" /> <CheckBox android:id="@+id/checktwo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/check2" /> <CheckBox android:id="@+id/checkthree" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/check3" /> </LinearLayout>
相关文章推荐
- Android--CheckBox复选框、RadioGroup和RadioButton及其使用
- android RadioButton和CheckBox组件的使用方法
- Android checkbox和radiobutton 以及Toast和AlertDialog的使用
- Android checkbox和radiobutton 以及Toast和AlertDialog的使用
- Android开发--RadioButton和CheckBox控件的使用
- Android零基础入门第20节:CheckBox和RadioButton使用大全
- Android开发--RadioButton和CheckBox控件的使用
- Android控件之Button,RadioButton,CheckBox,DatePicker,DatePickerDialog的使用
- Android开发历程_6(RadioButton和CheckBox的使用)
- Android零基础入门第20节:CheckBox和RadioButton使用大全
- Android选择控件,CheckBox和RadioButton使用大全
- Android中RadioButton和Checkbox的使用
- Android零基础入门第20节:CheckBox和RadioButton使用大全
- android中checkbox和radiobutton的使用
- 【按住你的心】——Android开发CheckBox&RadioButton控件的简单使用
- Android开发视频教程之十二(RadioGroup、RadioButton、CheckBox和Toast的使用)
- Android零基础入门第20节:CheckBox和RadioButton使用大全
- 【按住你的心】——Android开发CheckBox&RadioButton控件的简单使用
- Android UI学习笔记 之RadioButton和CheckBox的使用
- Android MVP模式 ListView中嵌入checkBox的使用