Radio.java
- package archie.android.activity;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Gravity;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import android.widget.Toast;
- public class Radio extends Activity {
- /**
- * 创建TextView对象
- * 创建RadioGroup对象
- * 创建4个RadioButton对象
- */
- TextView m_TextView;
- RadioGroup m_RadioGroup;
- RadioButton m_Radio1, m_Radio2, m_Radio3, m_Radio4;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- /**
- * 获得TextView对象
- * 获得RadioGroup对象
- * 获得4个RadioButton对象
- */
- m_TextView = (TextView) findViewById(R.id.TextView01);
- m_RadioGroup = (RadioGroup) findViewById(R.id.RadioGroup01);
- m_Radio1 = (RadioButton) findViewById(R.id.RadioButton1);
- m_Radio2 = (RadioButton) findViewById(R.id.RadioButton2);
- m_Radio3 = (RadioButton) findViewById(R.id.RadioButton3);
- m_Radio4 = (RadioButton) findViewById(R.id.RadioButton4);
- /* 设置事件监听 */
- m_RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId)
- {
- // TODO Auto-generated method stub
- if (checkedId == m_Radio2.getId())
- {
- DisplayToast("正确答案:" + m_Radio2.getText() + ",恭喜你,回答正确!");
- }
- else
- {
- DisplayToast("请注意,回答错误!");
- }
- }
- });
- }
- /* 显示Toast */
- public void DisplayToast(String str)
- {
- Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG);
- //设置toast显示的位置
- toast.setGravity(Gravity.TOP, 0, 220);
- //显示该Toast
- toast.show();
- }
- }
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"
- >
- <TextView
- android:id="@+id/TextView01"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- <RadioGroup
- android:id="@+id/RadioGroup01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_x="3px"
- android:layout_y="54px"
- >
- <RadioButton
- android:id="@+id/RadioButton1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/RadioButton1"
- />
- <RadioButton
- android:id="@+id/RadioButton2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/RadioButton2"
- />
- <RadioButton
- android:id="@+id/RadioButton3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/RadioButton3"
- />
- <RadioButton
- android:id="@+id/RadioButton4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/RadioButton4"
- />
- </RadioGroup>
- </LinearLayout>
String.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Android底层是基于什么操作系统?</string>
- <string name="app_name">RadioButton</string>
- <string name="RadioButton1">Windows</string>
- <string name="RadioButton2">Linux</string>
- <string name="RadioButton3">Moc os</string>
- <string name="RadioButton4">Java</string>
- </resources>
相关推荐
Eclipse V4.2.0编写的Android单选框应用实例。
android可无限嵌套选择的单选框,eclipse工程编译可直接运行。
单选框和复选框 单选按钮和复选按钮都是普通按钮Button的子类,所以可以使用所有Button的方法和属性。也有自己特有的属性方法 单选框 单选框就是在多个选项中只选择一个。 在Android中,单选按钮用RadioButton表示,...
在Android中用CheckBox+LinearLayout来实现一种多行单选按钮组的效果。效果图及讲解见:https://blog.csdn.net/ahuyangdong/article/details/82691961。github源码:https://github.com/ahuyangdong/SelectCustom
本文将通过radiogroup和radiobutton实现组内信息的单选, 其中radiogroup就是将radiobutton进行分组,同一管理和控制 同时实现默认选中情况,获取默认值.
一个简单的Android调用系统自带单选按钮的listView,并实现默认选项
本Demo通过两种途径实现了Listview的单选效果(自定义adapter) 1.点击Listview的item实现单选效果,就是...2.点击item上的单选框实现单选效果,就是点击单选框时,实现单选效果 3.点击Listview的item实现单选效果(改进版)
RecylerView配合ChekBox实现单选,解决了因为复用导致单选框混乱现象,androidStudio 可直接导入使用
不过运行起来发现了了一个bug—单选按钮不在是单选了.而且选择事件不会被监听到.这就要求我们去想办法了.其实实现起来也不难.只要多用几个RadioGroup就可以了(要在代码中处理一些事件)。 上代码: 1.xml中的...
本Demo通过两种途径实现了Listview的单选效果(自定义adapter) 1.点击Listview的item实现单选效果,就是点击item实现单选 2.点击item上的单选框实现单选效果,就是点击单选框时,实现单选效果
Android 树形结构开发demo,实现单选多选功能
项目要用到多行多列单选框,于是自己自定义了一个,有需要的童鞋刚好可以参考参考。
文档中包括Android实现对话框、列表框、单选复选框以及时间进度框各个文件所对应的代码以及运行截图,亲测可用!!
Android实现全癣单选多选功能实例,这个功能对于手机管理来说,相当有用了,一般情况下长按屏幕就会出现全选框,可多选 也可单选,选择之后可进行下一步操作,本例子就是实现这种功能,算是一个简单实用的模块实例吧...
主要为大家详细介绍了Android实现弹出列表、单选、多选框,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
Android开发——listview中嵌套checkBox复选框实现单选、全选删除列表内容 详情可以看我的博客http://blog.csdn.net/jxnk25/article/details/50358231
参考博文: http://blog.csdn.net/joe_storm/article/details/13773125
主要介绍了Android listview ExpandableListView实现多选,单选,全选,edittext实现批量输入的实例代码,非常不错,具有参考借鉴价值,需要的朋友可以参考下
android列表Listview单选效果源码,源码Listview单选,本Demo通过两种途径实现了Listview的单选效果(自定义adapter) 1.点击Listview的item实现...点击item上的单选框实现单选效果,就是点击单选框时,实现单选效果等。
主要介绍了Android ListView ImageView实现单选按钮的相关资料,需要的朋友可以参考下