Android开发笔记----radioGroup的使用
来源:互联网 发布:德阳儿童学编程 编辑:程序博客网 时间:2024/06/05 02:25
radioGroup
radioGroup是单项选择按钮,用来实现单选功能。
简单地创建一个radioGroup,和建立一个button,textview等基本相同,就是要写xml文件,只不过radioGroup需要在其中在写入radioButton,代码如下
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
只要在radioGroup中添加多个radioButton即可,这样便可以使用了。
对radioButton单选的操作
首先我们需要通过findviewbyid来将radioButton与activity中的变量想对应,然后我们在通过isChecked方法来确定是否被选中,但是由于radioGroup仅仅是个单选的控件,并不能实现我选中一个选项而进行接下来的操作,所以我们需要一个button来提交我们所选中的radioButton。代码如下:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.radio_layout);
radiobutton=(RadioButton) findViewById(R.id.radio0);
findViewById(R.id.btnSubmit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(radiobutton.isChecked())
{
new AlertDialog.Builder(radioAty.this).setTitle("判断").setMessage("回答正确").setPositiveButton("关闭",null).show();//这个是用来弹出一个小的对话框用于显示信息
}
else
{
new AlertDialog.Builder(radioAty.this).setTitle("判断").setMessage("回答错误").setPositiveButton("关闭",null).show();
}
}
});
}
- Android开发笔记----radioGroup的使用
- android学习笔记之RadioGroup的使用
- Android开发(20)--RadioGroup的使用
- android开发之RadioGroup的使用
- android RadioGroup的使用
- android应用开发揭秘例example4-7笔记(RadioGroup和RadioButton的使用与改进)
- 【Android学习笔记】RadioGroup,RadioButton的使用&CheckBox的使用
- Android自学笔记之RadioGroup和RadioButton的使用
- android 手机开发笔记--RadioGroup RadioButton
- Android RadioGroup控件的使用
- Android 多选一 RadioGroup的使用
- Android PopupWindow RadioGroup RadioButton 的使用
- Android—RadioGroup和RadioButton的使用
- Android的RadioGroup简单使用例子
- Android 应用开发笔记 - 单项选择(RadioGroup, RadioButton)
- Android开发笔记:基础控件之RadioGroup用法
- Android学习笔记——EditText、RadioGroup、CheckBox和Spinner的使用。
- Android开发之RadioGroup与RadioButton控件使用
- 程序员笔试面试常见题总结,更新ing
- MySQL字符串函数
- lua 删除key,value table中指定元素
- MD5算法了解(JAVA实现)
- BZOJ2882
- Android开发笔记----radioGroup的使用
- Linux下静态库和动态库的制作和使用
- link和@import的区别
- KMP算法最详细
- python编码笔记
- 日经春秋 20150822
- HDU 1290 献给杭电五十周年校庆的礼物(空间分割)
- POJ 3668 Game of Lines(n点最多有多少不平行直线)
- 日经社説 20150822 南北の緊張に警戒怠れない