Android——单选多选按钮的使用详解,2021最新Android算法相关面试大全

本文详细讲解了Android中RadioGroup和RadioButton的使用,通过实例展示了如何创建和监听单选按钮,并提供了Android面试相关知识,包括2021年最新面试题集。
摘要由CSDN通过智能技术生成

<RadioGroup

android:id="@+id/group1"

android:orientation=“horizontal”

android:layout_width=“match_parent”

android:layout_height=“wrap_content” >

<RadioButton

android:id="@+id/radio1"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:checked=“true”

android:text=“男”/>

<RadioButton

android:id="@+id/radio2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“女”/>

<View

android:layout_width=“match_parent”

android:layout_height=“2sp”

android:background="@android:color/holo_blue_dark"

android:layout_marginTop=“10sp”

android:layout_marginBottom=“10sp” />

<TextView

android:id="@+id/text1"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:textSize=“18sp”

android:text=“你吃饭了吗?”/>

<RadioGroup

android:id="@+id/group2"

android:layout_width=“match_parent”

android:layout_height=“wrap_content” >

<RadioButton

android:id="@+id/radio3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“吃了”/>

<RadioButton

android:id="@+id/radio4"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“没吃”/>

RadioActivity.java

package com.example.radioandcheckdemo;

import android.app.Activity;

import android.os.Bundle;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.RadioGroup.OnCheckedChangeListener;

import android.widget.Toast;

public class RadioActivity extends Activity implements OnCheckedChangeListener {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值