位置: 编程技术 - 正文

Android基础教程(七)之----单选项框RadioGroup的综合应用(android基础教程第三版电子版)

编辑:rootadmin

推荐整理分享Android基础教程(七)之----单选项框RadioGroup的综合应用(android基础教程第三版电子版),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:android基础教程电子版,android基础教程pdf下载,android基础入门,android基础教程pdf下载,android基础教程pdf下载,android基础教程电子版,android基础教程pdf下载,android基础教程第三版电子版,内容如对您有帮助,希望把文章链接给更多的朋友!

转自: 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只能做出单一选择(单选题).

首先,我们先设计一个TextView Widget ,以及一个RadioGroup ,并将该RadioGroup 内放置两个RadioButton ,默认为都不选择,在程序运行阶段,利用onCheckedChanged 作为启动事件装置,让User选择其中一个按钮,显示被选择的内容,最的将RadioButton 的选项文字显示于TextView 当中.

下面我们看一下效果图:

下面是涉及的相关代码:

string.xml:

Android基础教程(七)之----单选项框RadioGroup的综合应用(android基础教程第三版电子版)

<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, RadioGroupDemo</string> <string name="app_name">RadioGroupDemo</string> <string name="tr_radio_op1">帅哥</string> <string name="tr_radio_op2">美女</string> <string name="str_radio_question1">请问你是?</string> </resources>

主布局main.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!--第一個TextView --> <TextView android:id="@&#;id/myTextView" android:layout_width="px" android:layout_height="px" android:text="@string/str_radio_question1" android:textSize="sp" /> <!--建立一個RadioGroup --> <RadioGroup android:id="@&#;id/myRadioGroup" android:layout_width="px" android:layout_height="px" android:orientation="vertical" > <!--第一個RadioButton --> <RadioButton android:id="@&#;id/myRadioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tr_radio_op1" /> <!--第二個RadioButton --> <RadioButton android:id="@&#;id/myRadioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tr_radio_op2" /> </RadioGroup> </LinearLayout>

最后是主控制程序RadioGroupDemo.java:

package com.android.test;import android.app.Activity;import android.os.Bundle;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;public class RadioGroupDemo extends Activity { public TextView mTextView1; public RadioGroup mRadioGroup1; public RadioButton mRadio1,mRadio2; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /*取得 TextView、RadioGroup、RadioButton对象*/ mTextView1 = (TextView) findViewById(R.id.myTextView); mRadioGroup1 = (RadioGroup) findViewById(R.id.myRadioGroup); mRadio1 = (RadioButton) findViewById(R.id.myRadioButton1); mRadio2 = (RadioButton) findViewById(R.id.myRadioButton2); /*RadioGroup用OnCheckedChangeListener来运行*/ mRadioGroup1.setOnCheckedChangeListener(mChangeRadio); } private RadioGroup.OnCheckedChangeListener mChangeRadio = new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if(checkedId==mRadio1.getId()) { /*把mRadio1的内容传到mTextView1*/ mTextView1.setText(mRadio1.getText()); } else if(checkedId==mRadio2.getId()) { /*把mRadio2的内容传到mTextView1*/ mTextView1.setText(mRadio2.getText()); } } }; }

运行RadioGroupDemo.java ,将得到以上效果...今天就到这~

Fragment生命周期 官网帮助文档链接:

Android的事件处理-android学习之旅(四十四) androd事件处理简介控制飞机移动的简单实例packagepeng.liu.test;importandroid.app.ActionBar;importandroid.app.Activity;importandroid.graphics.Color;importandroid.os.Bundle;importandroid.

Android应用的自动升级、更新模块的实现 我们看到很多Android应用都具有自动更新功能,用户一键就可以完成软件的升级更新。得益于Android系统的软件包管理和安装机制,这一功能实现起来相当

标签: android基础教程第三版电子版

本文链接地址:https://www.jiuchutong.com/biancheng/386771.html 转载请保留说明!

上一篇:Fragment的使用(fragment详解)

下一篇:Fragment生命周期(fragment生命周期图)

  • 购买车辆保险的报告
  • 二手房缴纳个税是买方缴还是卖方缴?
  • 广告公司小规模税率
  • 企业城建税教育费附加和地教费的税率是多少
  • 资产负债和所有者权益三要素反映企业的
  • 收到固定资产抵账增值税计税基础
  • 融资租赁开具的发票是货物还是租金
  • 凭证工本费的账务处理
  • 员工年终福利发什么
  • 发票验证系统费用多少钱?
  • 安装工程中安装工程与市政路灯工程界定不正确的是
  • 小微企业免征增值税政策2023
  • 奖金发当月还是上月
  • 模拟评估了是什么意思
  • 日工资计算的三种方法
  • 银行增值税免税收入有哪些
  • win10禁止使用网络
  • 键盘插上电脑却不能用
  • 出口退税服务
  • 年终奖计提和发放
  • 总公司欠分公司的借款可以计提坏账
  • php怎么上传图片
  • 应收债权换入无形资产
  • 购买性支出和转移性支出的本质区别
  • 资产现金流量收益率计算方法
  • 停在花朵上,好像在认真的听同学们读课文修改病句
  • 店面装修费怎么算
  • 原生js获取document
  • 常用的绘图比例有哪些?
  • php错误和异常
  • 表关联查询语句
  • 质保金企业所得税纳税时间
  • 公司租房电费怎么算
  • 年底应交增值税销项税额要结平吗
  • 增值税专用发票是干什么用的
  • 给个体工商户打工受伤怎么办
  • 旅游业营改增怎么报税
  • 什么指的是土地面积
  • 公司收到服务费要交哪些税
  • 个人所得税不需要汇算清缴
  • 预付账款的账务处理视频教程
  • 销售退货和销售换货的区别
  • 人力资源外包服务包括哪些
  • 购货方收到销售方提供的发票怎么做分录
  • 暂估成本以后也没有票回来了
  • 企业清算处置固定资产
  • 银行收取服务费
  • 餐费发票报销需提供清单吗
  • 直接费用的定义
  • mysql 常用
  • sql语句实例大全
  • airdrop怎么用?
  • win10系统如何添加扫描仪
  • 组策略怎么用
  • win10安装更新
  • win7如何开机修复系统
  • linux vmware卸载
  • vim删除^m
  • Linux操作系统中怎么永久设置环境变量?
  • linux批量ping
  • win8.1删除所有内容并重新安装
  • 5.2光源
  • 景深图片的3d显示器
  • 使用jQuery的ajax方法向服务器发出get和post请求的方法
  • 怎样用在js中使用css的内容
  • Node.js中的事件循环是什么意思
  • 用批处理结束进程
  • unity 静态函数
  • 技术总结2000字
  • javascript 函数
  • ExpandableListView 实现分组购物车
  • python之父推荐的书
  • boost源码编译
  • 地方税务局怎么查企业信息
  • 河南电子税务局残保金怎么申报
  • 企业所得税季度申报表填报说明
  • 美国有汽车吗
  • 广东省电子税务局申报缴税操作指引
  • 一人可以在多家企业上班吗
  • 非关税壁垒英语翻译
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设