单选按钮的操作
来源:互联网 发布:mac更换硬盘克隆系统 编辑:程序博客网 时间:2024/05/17 17:38
布局文件main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Sex"> <TextView android:id="@+id/show" android:textSize="20px" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="你的性别是:" /> <RadioGroup android:id="@+id/sex" android:orientation="vertical" android:checkedButton="@+id/male" android:layout_width="fill_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/male" android:text="男" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/female" android:text="女" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </RadioGroup></LinearLayout>
定义Activity程序
package com.example.lenovo.myapplication;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;public class Sex extends AppCompatActivity { private TextView show ; private RadioGroup sex ; private RadioButton male ; private RadioButton female ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.show = (TextView) super.findViewById(R.id.show); this.sex = (RadioGroup) super.findViewById(R.id.sex); this.male = (RadioButton) super.findViewById(R.id.male); this.female = (RadioButton) super.findViewById(R.id.female); this.sex.setOnCheckedChangeListener(new OnCheckedChangeListenerImpl()); } private class OnCheckedChangeListenerImpl implements RadioGroup.OnCheckedChangeListener { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { String temp = null; if (Sex.this.male.getId()==checkedId){ temp = Sex.this.male.getText().toString(); } if (Sex.this.female.getId()==checkedId){ temp = Sex.this.female.getText().toString(); } Sex.this.show.setText("你的性别是:"+temp); } }}
0 0
- 单选按钮的操作
- 单选按钮的js选中操作
- 单选按钮(RadioBox)的操作
- 关于JS单选按钮复选按钮的一些操作
- js操作单选按钮
- 一些单选按钮和下拉列表框的操作
- 单选按钮组的操作,点击某个单选按钮操作底下相关组件,使其禁用或者允许
- jquery学习对单选按钮和复选按钮的操作
- jquery学习对单选按钮和复选按钮的操作
- Android中Radio单选按钮操作
- 用 jquery 操作 radio单选按钮
- Jquery操作radio单选按钮
- JQuery操作单选按钮以及复选按钮
- 单选按钮的值
- 单选按钮的用法
- PB的单选按钮
- 单选按钮的使用
- 单选按钮的实现
- mysql 创建字符串函数
- iOS之数据存取
- eclipse复制项目遇到的问题
- 初识JavaBean和EL表达式笔记
- linux 多工程的环境变量配置方法
- 单选按钮的操作
- 第一天
- 通用设备的动态DMA映射
- Drools学习
- soundPool简单用法
- Android 开发 之 JNI入门 - NDK从入门到精通
- 编译个性化的openwrt固件
- ImageView实现画画板的功能
- Adapter控件获取失败