第八节--控件(一)RadioGroup,RadioButton,CheckBox,Toast
2011-03-16 11:48
561 查看
RadioGroup:
RadioButton:
原意:
A radio button is a two-states button that can be either checked or unchecked. When the radio button is unchecked, the user can press or click it to check it.
译文:
单选按钮是两种状态的按钮,可以是选中或不选中状态。当单选按钮未被选中,用户可以按下或点击它来选中它。
CheckBox:
原意:
A checkbox is a specific type of two-states button that can be either checked or unchecked
译文:
一个checkbox是一个指定的两种状态类型的按钮,它要么被选中要么不被选中。
Toast:
原意:
A toast is a view containing a quick little message for the user. The toast class helps you create and show those.
译文:
一个Toast是一个快速显示一小段信息给用户的视图。toast类可以帮组我们创建和显示这些信息。
代码示例:
演示效果:
原意:
This class is used to create a multiple-exclusion scope for a set of radio buttons. Checking one radio button that belongs to a radio group unchecks any previously checked radio button within the same group.
Intially, all of the radio buttons are unchecked. While it is not possible to uncheck a particular radio button, the radio group can be cleared to remove the checked state.
译文:
这个类是用来创建具有相互排斥的一个可选择radio按钮。在同一组内,选择其中一个按钮就预示着要取消另一个按钮的选择。
最初,单选按钮都是未选中。如果一个radio组被移除和取消,是不可能去选择一个radio按钮的。
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.LinearLayout | |||
↳ | android.widget.RadioGroup |
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.widget.TextView | ||||
↳ | android.widget.Button | ||||
↳ | android.widget.CompoundButton | ||||
↳ | android.widget.RadioButton |
A radio button is a two-states button that can be either checked or unchecked. When the radio button is unchecked, the user can press or click it to check it.
译文:
单选按钮是两种状态的按钮,可以是选中或不选中状态。当单选按钮未被选中,用户可以按下或点击它来选中它。
CheckBox:
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.widget.TextView | ||||
↳ | android.widget.Button | ||||
↳ | android.widget.CompoundButton | ||||
↳ | android.widget.CheckBox |
A checkbox is a specific type of two-states button that can be either checked or unchecked
译文:
一个checkbox是一个指定的两种状态类型的按钮,它要么被选中要么不被选中。
Toast:
java.lang.Object | |
↳ | android.widget.Toast |
A toast is a view containing a quick little message for the user. The toast class helps you create and show those.
译文:
一个Toast是一个快速显示一小段信息给用户的视图。toast类可以帮组我们创建和显示这些信息。
代码示例:
java代码: public class RadioTest extends Activity { //对控件对象进行声明 private RadioGroup firstGroup = null; private RadioGroup secondGroup = null; private RadioButton femaleButton = null; private RadioButton maleButton = null; private RadioButton sunzoneButton = null; private RadioButton pro360Button = 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); //通过调用findViewById方法,获取对应Id控件的对象 firstGroup = (RadioGroup)findViewById(R.id.firstGroup); secondGroup = (RadioGroup)findViewById(R.id.secondGroup); femaleButton = (RadioButton)findViewById(R.id.femaleButton); maleButton = (RadioButton)findViewById(R.id.maleButton); sunzoneButton=(RadioButton)findViewById(R.id.sunzoneButton); pro360Button=(RadioButton)findViewById(R.id.edu360Button); swimBox = (CheckBox)findViewById(R.id.swim); runBox = (CheckBox)findViewById(R.id.run); readBox = (CheckBox)findViewById(R.id.read); //为RadioGroup设置监听器 firstGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(femaleButton.getId() == checkedId){ Toast.makeText(RadioTest.this, "famle", Toast.LENGTH_SHORT).show(); } else if(maleButton.getId() == checkedId) { System.out.println("male"); Toast.makeText(RadioTest.this, "male", Toast.LENGTH_SHORT).show(); } } }); secondGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(sunzoneButton.getId()==checkedId){ Toast.makeText(RadioTest.this, "森纵教育", Toast.LENGTH_LONG).show(); }else if(pro360Button.getId()==checkedId){ Toast.makeText(RadioTest.this, "职业教育360", Toast.LENGTH_SHORT).show(); } } }); //为多选按钮添加监听器 swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked) { Toast.makeText(RadioTest.this, "你选择了swim", Toast.LENGTH_SHORT).show(); System.out.println("swim is checked"); } else { System.out.println("swim is unchecked"); Toast.makeText(RadioTest.this, "你取消了swim", Toast.LENGTH_SHORT).show(); } } }); runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked) { Toast.makeText(RadioTest.this, "你选择了run", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(RadioTest.this, "你取消了run", Toast.LENGTH_SHORT).show(); } } }); readBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked) { System.out.println("read is checked"); Toast.makeText(RadioTest.this, "你选择了read", Toast.LENGTH_SHORT).show(); } else { System.out.println("read is unchecked"); Toast.makeText(RadioTest.this, "你取消了read", Toast.LENGTH_SHORT).show(); } } }); } }
布局文件: <?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="控件Test" /> <RadioGroup android:id="@+id/firstGroup" 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> <TextView android:layout_width="100px" android:layout_height="2dp" android:background="#00ddcc" /> <RadioGroup android:id="@+id/secondGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <RadioButton android:id="@+id/sunzoneButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="森纵教育" /> <RadioButton android:id="@+id/edu360Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="职业教育" /> </RadioGroup> <TextView android:layout_width="fill_parent" android:layout_height="2dp" android:background="#00ddcc" /> <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" /> <TextView android:layout_width="fill_parent" android:layout_height="2dp" android:background="#00ddcc" /> </LinearLayout>
演示效果:
原意:
This class is used to create a multiple-exclusion scope for a set of radio buttons. Checking one radio button that belongs to a radio group unchecks any previously checked radio button within the same group.
Intially, all of the radio buttons are unchecked. While it is not possible to uncheck a particular radio button, the radio group can be cleared to remove the checked state.
译文:
这个类是用来创建具有相互排斥的一个可选择radio按钮。在同一组内,选择其中一个按钮就预示着要取消另一个按钮的选择。
最初,单选按钮都是未选中。如果一个radio组被移除和取消,是不可能去选择一个radio按钮的。
相关文章推荐
- Android开发--控件之RadioGroup、RadioButton、CheckBox、Toast
- Android常见控件之RadioGroup,RadioButton,CheckBox和Toast
- 【android基础学习之三】——基础控件Toast,EditText,RadioGroup,RadioButton
- Android开发视频教程之十二(RadioGroup、RadioButton、CheckBox和Toast的使用)
- RadioGroup,RadioButton CheckBox控件的使用
- 01-12:RadioGroup、RadioButton、CheckBox、Toast的用法
- (转)android常用控件(二) RadioGroup RadioButton CheckBox Toast的使用
- android开发学习笔记——稍复杂控件 RadioGroup,CheckBox,Toast
- Activity常用控件二——RadioGroup、RadioButton、CheckBox的使用
- android应用开发笔记---常用控件RadioGroup和RadioButton及Toast
- RadioGroup、RadioButton(单选按钮)、CheckBox(多选按钮)和Toast的使用方法
- Activity常用控件二——RadioGroup、RadioButton、CheckBox的使用
- Android-基本控件(CheckBox,RadioGroup,RadioButton)
- CheckBox控件及OnCheckedChangeListener监听器的使用,RadioGroup及RadioButton的使用
- Android控件之CheckBox、RadioGroup、RadioButton
- mars老师的第12讲——常用控件(2)RadioGroup/checkBox/Toast
- Android UI控件之RadioGroup、RadioButton
- android学习笔记05(RadioGroup,CheckBox,Toast)
- Android--CheckBox复选框、RadioGroup和RadioButton及其使用
- Android控件RadioButton&RadioGroup&CheckBox