Android 开发笔记___RadioButton

horizontal

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="match_parent"
 3     android:layout_height="match_parent"
 4     android:orientation="vertical"
 5     android:padding="10dp" >
 6
 7     <TextView
 8         android:layout_width="match_parent"
 9         android:layout_height="wrap_content"
10         android:text="请选择您的性别"
11         android:textColor="#000000"
12         android:textSize="17sp" />
13
14     <RadioGroup
15         android:id="@+id/rg_sex"
16         android:layout_width="match_parent"
17         android:layout_height="wrap_content"
18         android:orientation="horizontal" >
19
20         <RadioButton
21             android:id="@+id/rb_male"
22             android:layout_width="0dp"
23             android:layout_height="wrap_content"
24             android:layout_weight="1"
25             android:checked="false"
26             android:text="男"
27             android:textColor="#000000"
28             android:textSize="17sp" />
29
30         <RadioButton
31             android:id="@+id/rb_female"
32             android:layout_width="0dp"
33             android:layout_height="wrap_content"
34             android:layout_weight="1"
35             android:checked="false"
36             android:text="女"
37             android:textColor="#000000"
38             android:textSize="17sp" />
39     </RadioGroup>
40
41     <TextView
42         android:id="@+id/tv_sex"
43         android:layout_width="match_parent"
44         android:layout_height="wrap_content"
45         android:textColor="#000000"
46         android:textSize="17sp" />
47
48     <View
49         android:layout_width="match_parent"
50         android:layout_height="20dp" />
51
52 </LinearLayout>
 1 package com.example.alimjan.hello_world;
 2
 3 import android.content.Context;
 4 import android.content.Intent;
 5 import android.os.Bundle;
 6 import android.support.v7.app.AppCompatActivity;
 7 import android.widget.RadioGroup;
 8 import android.widget.TextView;
 9
10 /**
11  * Created by alimjan on 7/2/2017.
12  */
13
14 public class class_3_2_3 extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
15
16     private final static String TAG = "RadioHorizontalActivity";
17     private TextView tv_sex;
18
19     @Override
20     protected void onCreate(Bundle savedInstanceState) {
21         super.onCreate(savedInstanceState);
22         setContentView(R.layout.code_3_2_3);
23         tv_sex = (TextView) findViewById(R.id.tv_sex);
24         RadioGroup rg_sex = (RadioGroup) findViewById(R.id.rg_sex);
25         rg_sex.setOnCheckedChangeListener(this);
26     }
27
28     @Override
29     public void onCheckedChanged(RadioGroup group, int checkedId) {
30         if (checkedId == R.id.rb_male) {
31             tv_sex.setText("哇哦,你是个帅气的男孩");
32         } else if (checkedId == R.id.rb_female) {
33             tv_sex.setText("哇哦,你是个漂亮的女孩");
34         }
35     }
36
37     public static void startHome(Context mContext) {
38         Intent intent = new Intent(mContext, class_3_2_3.class);
39         mContext.startActivity(intent);
40     }
41 }

vertical

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="match_parent"
 3     android:layout_height="match_parent"
 4     android:orientation="vertical"
 5     android:padding="10dp" >
 6
 7     <TextView
 8         android:layout_width="match_parent"
 9         android:layout_height="wrap_content"
10         android:text="请选择您的婚姻状况"
11         android:textColor="#000000"
12         android:textSize="17sp" />
13
14     <RadioGroup
15         android:id="@+id/rg_marry"
16         android:layout_width="match_parent"
17         android:layout_height="wrap_content"
18         android:orientation="vertical" >
19
20         <RadioButton
21             android:id="@+id/rb_unmarried"
22             android:layout_width="wrap_content"
23             android:layout_height="wrap_content"
24             android:padding="5dp"
25             android:button="@drawable/radio_selector"
26             android:text="未婚"
27             android:textColor="#000000"
28             android:textSize="17sp" />
29
30         <RadioButton
31             android:id="@+id/rb_married"
32             android:layout_width="wrap_content"
33             android:layout_height="wrap_content"
34             android:padding="5dp"
35             android:button="@null"
36             android:drawableLeft="@drawable/radio_selector"
37             android:drawablePadding="10dp"
38             android:text="已婚"
39             android:textColor="#000000"
40             android:textSize="17sp" />
41     </RadioGroup>
42
43     <TextView
44         android:id="@+id/tv_marry"
45         android:layout_width="match_parent"
46         android:layout_height="wrap_content"
47         android:textColor="#000000"
48         android:textSize="17sp" />
49
50 </LinearLayout>
 1 package com.example.alimjan.hello_world;
 2
 3 import android.content.Context;
 4 import android.content.Intent;
 5 import android.os.Bundle;
 6 import android.support.v7.app.AppCompatActivity;
 7 import android.widget.RadioGroup;
 8 import android.widget.TextView;
 9
10 /**
11  * Created by alimjan on 7/2/2017.
12  */
13
14 public class class_3_2_3_2 extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
15
16     private final static String TAG = "RadioVerticalActivity";
17     private TextView tv_marry;
18
19     @Override
20     protected void onCreate(Bundle savedInstanceState) {
21         super.onCreate(savedInstanceState);
22         setContentView(R.layout.code_3_2_3_2);
23         tv_marry = (TextView) findViewById(R.id.tv_marry);
24         RadioGroup rg_marry = (RadioGroup) findViewById(R.id.rg_marry);
25         rg_marry.setOnCheckedChangeListener(this);
26     }
27
28     @Override
29     public void onCheckedChanged(RadioGroup group, int checkedId) {
30         if (checkedId == R.id.rb_married) {
31             tv_marry.setText("哇哦,祝你早生贵子");
32         } else if (checkedId == R.id.rb_unmarried) {
33             tv_marry.setText("哇哦,你的前途不可限量");
34         }
35     }
36
37     public static void startHome(Context mContext) {
38         Intent intent = new Intent(mContext, class_3_2_3_2.class);
39         mContext.startActivity(intent);
40     }
41
42 }
时间: 2024-08-09 19:53:45

Android 开发笔记___RadioButton的相关文章

Android开发笔记(一百零三)地图与定位SDK

集成地图SDK 国内常用的地图SDK就是百度和高德了,二者的用法大同小异,可按照官网上的开发指南一步步来.下面是我在集成地图SDK时遇到的问题说明: 1.点击基本地图功能选项,不能打开地图,弹出"key验证出错!请在AndroidManifest.xml文件中检查key设置的"的红色字提示.查看日志提示"galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy&

[APP] Android 开发笔记 003

接上节 [APP] Android 开发笔记 002 5. 使用ant release 打包 1)制作 密钥文件 release.keystore (*.keystore) keytool -genkey -v -keystore "release.keystore" -alias "release" -keyalg "RSA" -validity "10000" 这里需要注意的是: -keystore "relea

《ArcGIS Runtime SDK for Android开发笔记》——(10)、ArcGIS Runtime SDK支持的空间数据类型

1.前言 移动端的数据来源非常重要,它决定了移动端功能的实现.早期的ArcGIS Android API中,主要以接入在线的数据源为主,因此主要实现在线的地图浏览.查询和路径分析.地理处理等从操作:在v1.0.1版本中,ArcGIS移动产品第一次可以加载松散型切片,自此逐渐掀开了对本地离线数据源的支持,也因此可以在移动端实现越来越受欢迎的离线功能.现在最新的10.2.7 API离线支持数据主要包括紧凑型切片.tpk切片包..geodatabase..shp文件.地名地址库.网络数据集. 转载请注

Android开发笔记--hello world 和目录结构

原文:Android开发笔记--hello world 和目录结构 每接触一个新东西 都有一个hello world的例子. 1.新建项目 2.配置AVD AVD 没有要新建个,如果不能创建 运行SDK Manager更新 3.接着运行就可以了 第一次启动要1分多钟 不要关 4.添加代码 5.接着在运行就OK了 目录结构 1.src - 用于放置源程序 2.gen - 自动生成 R.java 文件,用于引用资源文件(即 res 目录下的数据) 3.assets - 用于放置原始文件,Androi

Android开发笔记(一百一十六)网络学习资源

知名网站 本系列的开发笔记,对Android开发来说只是沧海一瓢,还有更多的技术等待我们去汲取.下面列出几个常用的开发网站,供初学者上路: 首先当然是国内首屈一指的技术网站csdn啦,csdn提供了众多频道,包括博客.论坛.下载.问答等等,其中博客专栏提供了最新的技术文章,值得推荐.csdn博客专栏的地址是 http://blog.csdn.net/column.html 下面是csdn博客专栏的网页截图: 其次是国外有名的开源网站GitHub,这里有众多的开源项目源码,是开发者分享代码的乐园.

Android开发笔记(八十八)同步与加锁

同步synchronized 同步方法 synchronized可用来给方法或者代码块加锁,当它修饰一个方法或者一个代码块的时候,同一时刻最多只有一个线程执行这段代码.这就意味着,当两个并发线程同时访问synchronized代码块时,两个线程只能是排队做串行处理,另一个线程要等待前一个线程执行完该代码块后,才能再次执行synchronized代码块. 使用synchronized修饰某个方法,该方法便成为一个同步方法,在同一时刻只能有一个线程执行该方法.可是,synchronized的锁机制太

android开发笔记1

1.强制横屏,不能转屏 在AndroidManifest中需要的activity里: <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">   <activity android:name=".GestureFlip"     android:label="@string/app_name"   

ANDROID开发笔记(二)

动机: 开发的一个背单词的软件. 不会实现划屏的特性. 方法: 第一步尝试: 在MainActivity中, 增加以下代码后, 如果在视图的空白处点击时, 文本框中的时间就会发生改变. @Override     public boolean onTouchEvent(MotionEvent event) {         // TODO Auto-generated method stub         final TextView textview = (TextView)findVie

ANDROID开发笔记(一)

manifest, 英['m?n?fest] vt. 显示,表明;证明;使显现 adj. 明白的,明显的 n. 货单,旅客名单 wrap_content, 根据实际内容调整   原来新版的ADB已经支持无线连接了,这样对于我经常使用ADB安装软件的用户可谓是一大福音,这意味着91助手.腕豆夹这类的软件估计在不久的将来也能支持这个功能了,当然前提是你必须下载ADB(PC)软件,另外在手机侧你需要安装一款ADB wireless widget这个插件.使用方法: 1. 先在手机上执行adb wire