Android开发笔记:基础控件之RadioGroup用法
2017-08-31 16:35
423 查看
1 java文件
/***
*/
package com.example.ht.test.control;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
/**
* @author Administrator
*
*/
public class Ht_RadioGroup extends Activity {
private RadioButton radioRight;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO 自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.ht_radiogroup);
radioRight = (RadioButton) findViewById(R.id.radio0);
findViewById(R.id.btnSubmit).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
if(radioRight.isChecked()){
new AlertDialog.Builder(Ht_RadioGroup.this).setTitle("判断").setMessage("回答正确").setPositiveButton("关闭", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO 自动生成的方法存根
System.exit(0);
}
}).show();
}
else{
new AlertDialog.Builder(Ht_RadioGroup.this).setTitle("判断").setMessage("回答错误").setPositiveButton("关闭", null).show();
}
}
});
}
}
2 布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<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:text="A(正确)" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C" />
</RadioGroup>
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交" />
</LinearLayout>
3 效果图
相关文章推荐
- Android开发笔记:基础控件之DatePicker用法
- android应用开发笔记---常用控件RadioGroup和RadioButton及Toast
- android开发学习笔记——稍复杂控件 RadioGroup,CheckBox,Toast
- Android开发笔记----radioGroup的使用
- Android 应用开发笔记 - 单项选择(RadioGroup, RadioButton)
- Android RadioGroup和RadioButton控件简单用法示例
- Android开发笔记:基本控件之Spinner用法
- 【Android开发学习笔记】【第四课】基础控件的学习
- android应用开发揭秘例example4-7笔记(RadioGroup和RadioButton的使用与改进)
- Android控件笔记——使用RadioGroup和RadioButton实现单选效果
- 【android基础学习之三】——基础控件Toast,EditText,RadioGroup,RadioButton
- Android开发笔记:Android控件之listview基础篇
- android应用开发--------------看RadioGroup源码,写类似单选选项卡的集成控件(如底部导航,tab等等)
- 【幻化万千戏红尘】qianfeng-Android-Day03-RadioButton及RadioGroup的用法、CheckBox、ProgressBar基础学习:
- Android开发之四(五):常用控件之单项选择(RadioGroup和RadioButton)
- Android开发之UI控件(1)-CheckBox、DataPicker、RadioGroup、ProgressBar、Spinner
- android应用开发--------------看RadioGroup源代码,写相似单选选项卡的集成控件(如底部导航,tab等等)
- Android编程开发之RadioGroup用法实例
- 【Android开发学习笔记】【第四课】基础控件的学习
- 【Android开发学习26】界面控件之选项组件(RadioGroup和CheckBox)