我使用的AndroidStudio版本是3.2的,因为据说这个版本比现在最新的3.5版本的稳定。此外我在创建项目的时候兼容的最小版本为AndroidStudio5.0,api21,我下载的akp如上图所示,如果将项目搬过去出了问题,请先查看这些对不对。

以下是MainActivity文件

package com.li.a43;import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button rbdetermine =(Button) findViewById(R.id.rbdetermine) ;rbdetermine.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {RadioButton spring =(RadioButton) findViewById(R.id.rbspring);RadioButton rbsummer =(RadioButton) findViewById(R.id.rbsummer);RadioButton rbautumu =(RadioButton) findViewById(R.id.rbautumu);RadioButton rbwinter =(RadioButton) findViewById(R.id.rbwinter);TextView txtResult = (TextView) findViewById(R.id.txtResult);//TextView txtResulta = (TextView) findViewById(R.id.txtResulta);//txtResult.setText("您选择的是春");if  (spring.isChecked()) {txtResult.setText("您选择的是春");}else if(rbsummer.isChecked()){txtResult.setText("您选择的是夏");}else if(rbautumu.isChecked()){txtResult.setText("您选择的是秋");}else if(rbwinter.isChecked()){txtResult.setText("您选择的是冬");}}});}}

以下为activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"><TextViewandroid:id="@+id/tvchoose"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/choose"/><RadioButtonandroid:id="@+id/rbspring"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/spring"/><RadioButtonandroid:id="@+id/rbsummer"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/summer"/><RadioButtonandroid:id="@+id/rbautumu"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/autumu"/><RadioButtonandroid:id="@+id/rbwinter"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/winter"/><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"><RadioButtonandroid:id="@+id/rbdetermine"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="false"android:text="@string/determine"tools:layout_editor_absoluteX="0dp"tools:layout_editor_absoluteY="170dp" /><TextViewandroid:id="@+id/txtResulta"android:layout_width="wrap_content"android:layout_height="wrap_content" /></RadioGroup><TextViewandroid:id="@+id/txtResult"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/colorPrimary" /></RadioGroup></android.support.constraint.ConstraintLayout>

以下为string.xml

<resources><string name="app_name">4.3</string><string name="spring">春</string><string name="summer">夏</string><string name="autumu">秋</string><string name="winter">冬</string><string name="choose">请选择你最喜欢的一个季节</string><string name="determine">确定</string>
</resources>

1.package com.li.a43;

li是创建项目时要求填的公司的名字
a43则是该项目的名字

2.Button rbdetermine =(Button) findViewById(R.id.rbdetermine) ;

这是实例化一个Button对象rbdetermine
然后对这个对象设置监听器,用来在这个按钮被点击的时候做出反应
ischedked函数用于判断RadioButton是否被选中,并输出文本
txtResult是TextView的一个实例化对象


以下为上传的文件
https://download.csdn.net/download/programmer9/11959425

AndroidStudio下利用Radiogroup和RadioButton写春夏秋冬的选择相关推荐

  1. 一篇博客带你熟悉Eclipse、AndroidStudio下搭建NDK环境(内有Demo)

    文章目录 一.NDK可以干什么 二.NDK开发环境搭建 三.一个简单的NDK小案例的编写 一.NDK可以干什么 NDK:(Native Development Kit),原生开发工具包是一组可以让您在 ...

  2. android中radiogroup作用,Android View系列---RadioGroup与RadioButton

    RadioGroup与RadioButton配合实现一组数据的单选问题. 插播一条信息,在设置RadioButton的textColor的选中效果时,不能在drawable中创建想xml,得在res/ ...

  3. RadioGroup中RadioButton默认选中问题

    当一个RadioGroup(其实只要在同一个父布局)中有若干个RadioButton时,RadioButton之间存在着互斥关系, 也就是说只能选中一个RadioButton.但是如果我们需要默认选中 ...

  4. android radiobutton 监听事件,Android View系列---RadioGroup与RadioButton

    RadioGroup与RadioButton配合实现一组数据的单选问题. 插播一条信息,在设置RadioButton的textColor的选中效果时,不能在drawable中创建想xml,得在res/ ...

  5. Delphi下利用WinIo模拟鼠标键盘详解

    本文最早在编程论坛上发表,文章地址:http://programbbs.com/bbs/view12-17207-1.htm,相关文件可以在上述地址的页面中下载.转载时请注明出处. 前言 一日发现Se ...

  6. Centos6.3下利用open***部署远程×××服务

    Centos6.3下利用open***部署远程×××服务 open***是一款在LINUX网关服务器使用的开源的×××软件,顾名思义,其实就是用来打通一条安全的虚拟专用通道,实现用户远程办公,获取内网 ...

  7. java 内存映射文件进程间通讯_[转]Windows环境下利用“共享内存”实现进程间通信的C/C++代码---利用CreateFileMapping和MapViewOfFile...

    进程间的通信方式有很多种, 上次我们说了最傻瓜的"共享外存/文件"的方法. 那么, 在本文中, 我们即将学习"共享内存"的方式实现进程间的通信, 这是IPC最快 ...

  8. RadioGroup结合RadioButton使用切换Fragment片段

    界面布局activity_lan_qiu,代码xml设置如下: <?xml version="1.0" encoding="utf-8"?> < ...

  9. 如何利用结构化思维写好分析报告?

    在讲如何写好分析报告前,我们先来讲讲何为结构化思维?结构化思维是一种从无序到有序的思考过程. 举个例子,现在有个问题:如何把200ml的水装进100ml的杯子?大家可能有各种各样的答案:把水冻成冰,用 ...

最新文章

  1. php修改为ajax,php通过ajax实现双击table修改内容
  2. Camera框架初探
  3. 成功解决eric6 Create Dialog Code XXX.py exists but does not contain any classes
  4. 中国大学MOOC 计算机组成原理第4章 测试(下)
  5. Ajax step by step
  6. .NET6 中的 PriorityQueue
  7. Hive 终于等来了 Flink
  8. 用Python抓取网页并解析
  9. ELK Stack 日志平台性能优化实践
  10. python random模块安装_Python中的For循环和Random模块
  11. java 字符单词匹配_如何使用Java RegEx匹配单词字符?
  12. 修改Linux文件格式为unix
  13. 搭建以图搜图检索系统
  14. dma循环刷新oled屏幕
  15. 安徽大学计算机复试刷人比例,658人进复试刷掉564多人!盘点21复试比奇高、刷人狠的院校专业...
  16. java1.8离线安装包_离线安装JDK1.8
  17. 创意、实现和合作:一次原创H5的尝试
  18. Linux服务器下载日志到本地
  19. 如何实时计算日累计逐单资金流
  20. python二进制和图片转换

热门文章

  1. UART、RS232、RS485、IIC、SPI、CAN、CANFD、LIN、flexray、以太网等总线介绍
  2. python中的name mangle机制
  3. UNIX故障--sun m4000服务器故障硬盘更换案例
  4. 本科学c语言程序设计吗,C语言程序设计(本科).doc
  5. 2021QS 榜单发布:计算机专业排名 MIT 斯坦福霸榜,清华北大进入前 20
  6. 物理专业出身的Flash业余爱好者喜获Adobe Flash开发大赛一等奖
  7. 新的换脸模型FaceShifter论文解读
  8. 无意中发现的一个好设计:不浸水的香皂盒
  9. Using mockito in java
  10. 荣耀笔记本MagicBook Pro 体验~学生族走过路过别错过