android学习笔记05(RadioGroup,CheckBox,Toast)
来源:互联网 发布:网站源码交流论坛 编辑:程序博客网 时间:2024/05/16 00:46
java类:
package tk.layput_07;import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast;public class Layout07 extends Activity { 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.layout07); 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); genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if(femaleButton.getId()==checkedId){ System.out.println("famale"); Toast.makeText(Layout07.this, "famle", Toast.LENGTH_SHORT).show(); }else if(maleButton.getId()==checkedId){ System.out.println("male"); Toast.makeText(Layout07.this, "male", Toast.LENGTH_SHORT).show(); } } }); swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ System.out.println("swim is checked"); }else{ System.out.println("swim is unchecked"); } } }); readBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ System.out.println("swim is checked"); }else{ System.out.println("swim is unchecked"); } } }); runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ System.out.println("swim is checked"); }else{ System.out.println("swim is unchecked"); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.layout07, menu); return true; } }
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" > <TextView android:id="@ id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <RadioGroup android: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> <CheckBox android:id="@ id/swim" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/swim" /> <CheckBox android:id="@ id/run" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/run" /> <CheckBox android:id="@ id/read" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/read" /> </LinearLayout>
0 0
- android学习笔记05(RadioGroup,CheckBox,Toast)
- android开发学习笔记——稍复杂控件 RadioGroup,CheckBox,Toast
- Android常用控件(一)【RadioGroup、RadioButton、CheckBox、Toast】
- Android之CheckBox,RadioGroup(笔记)
- Android之CheckBox,RadioGroup(笔记)
- 【Android学习笔记】RadioGroup,RadioButton的使用&CheckBox的使用
- (转)android常用控件(二) RadioGroup RadioButton CheckBox Toast的使用
- Android常见控件之RadioGroup,RadioButton,CheckBox和Toast
- Android开发--控件之RadioGroup、RadioButton、CheckBox、Toast
- 第八节--控件(一)RadioGroup,RadioButton,CheckBox,Toast
- Android学习笔记——EditText、RadioGroup、CheckBox和Spinner的使用。
- Android-基本控件(CheckBox,RadioGroup,RadioButton)
- Android Toast 学习笔记
- 雾山的Anrdoid学习笔记---CheckBox,RadioGroup&RadioButton
- 雾山的Anrdoid学习笔记---CheckBox,RadioGroup&RadioButton .
- android学习笔记(三)Toast
- Android学习笔记6——常用控件RadioButton/CheckBox/Toast
- RadioGroup、RadioButton(单选按钮)、CheckBox(多选按钮)和Toast的使用方法
- android学习笔记03(RelativeLayout)
- android学习笔记04(LinearLayout的嵌套)
- Jsp与Servlet之间的传值
- android学习笔记06(第一个程序)
- pl/sql自动填充
- android学习笔记05(RadioGroup,CheckBox,Toast)
- 漫谈 Clustering (3): Gaussian Mixture Model
- 利用xerces-c库将xml串转换为类
- android学习笔记07(activity跳转,通信,及发短信)
- android学习笔记08(activity通信的一个实例--乘法计算器)
- linux查看文件类型
- android学习笔记09(activity的生命周期)
- android学习笔记10(activity的死亡,菜单,及对话框)
- android学习笔记11(Adapter初级学习)