android 单选,复选按钮,以及toast
来源:互联网 发布:linux编辑只读文件 编辑:程序博客网 时间:2024/05/21 13:47
RadioTest.java
package mars.activity07;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.Toast;public class RadioTest extends Activity { /** Called when the activity is first created. *///对控件对象进行声明private RadioGroup genderGroup = null;private RadioButton femaleButton = null;private RadioButton maleButton = null;private CheckBox swimBox = null;private CheckBox runBox = null;private CheckBox readBox = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.radio); //通过控件的ID来得到代表控件的对象 genderGroup = (RadioGroup)findViewById(R.id.genderGroup); femaleButton = (RadioButton)findViewById(R.id.femaleButton); maleButton = (RadioButton)findViewById(R.id.maleButton); swimBox = (CheckBox)findViewById(R.id.swim); runBox = (CheckBox)findViewById(R.id.run); readBox = (CheckBox)findViewById(R.id.read); //为RadioGroup设置监听器,需要注意的是,这里的监听器和Button控件的监听器有所不同 genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubif(femaleButton.getId() == checkedId){System.out.println("famale");Toast.makeText(RadioTest.this, "famle", Toast.LENGTH_SHORT).show();}else if(maleButton.getId() == checkedId){System.out.println("male");}}}); //为多选按钮添加监听器 swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){System.out.println("swim is checked");}else{System.out.println("swim is unchecked");}}}); runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){System.out.println("run is checked");}else{System.out.println("run is unchecked");}}}); readBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){System.out.println("read is checked");}else{System.out.println("read is unchecked");}}}); } }
layout/main.xml
<?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" ><TextViewandroid:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /><RadioGroupandroid:id="@+id/genderGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <RadioButton android:id="@+id/femaleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/female" /> <RadioButton android:id="@+id/maleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/male" /></RadioGroup><CheckBoxandroid:id="@+id/swim" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/swim" /><CheckBoxandroid:id="@+id/run" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/run" /><CheckBoxandroid:id="@+id/read" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/read" /></LinearLayout>
- android 单选,复选按钮,以及toast
- Android常用控件(按钮事件,Toast,单选复选,时间日期选择框)解析
- 绿色单选按钮以及复选框
- JQuery操作单选按钮以及复选按钮
- Android之复选按钮、单选按钮、开关按钮
- 单选按钮&复选按钮
- 【Android】标签页、计时器、单选按钮、复选按钮
- Android 单选按钮和复选框事例
- Android-单选按钮RadioButton和复选框checkbox
- android单选按钮(RadioButton)、复选框(CheckBox)
- Android练习-----单选按钮(RadioButton) && 复选框(CheckBox)
- Android中的 单选按钮和复选框
- Android--(11)--解读单选(RadioButton)和复选(CheckBox)按钮
- Android学习笔记17---单选按钮&复选框
- android 复选单选按钮 CheckBox和RadioButton
- 单选按钮和复选按钮
- 单选按钮和复选按钮
- Android用户界面基础之CheckBox(复选按钮)、RadioButton(单选按钮)学习
- 常用的Mac快捷键
- tp-link后门
- 嵌入式程序员C语言测试题
- zend studio常见问题解答 破解
- OpenStack最新版本Folsom架构解析
- android 单选,复选按钮,以及toast
- Google和Microsoft的地图服务--李开复
- 响应式web网站资料收集
- 为什么中国没有出现扎克伯格
- mini6410的nfs文件系统uboot参数设置&&nand分区
- HTTP协议详解(真的很经典)
- JavaScript学习笔记(一)
- 响应式web初接触
- 一些排序算法总结