Android——单选多选按钮的使用详解

android:orientation=“vertical”

tools:context=“ r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}” >

<Button

android:id=“@+id/button1”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“RadioActivity单选” />

<Button

android:id=“@+id/button2”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“CheckActivity多选” />

MainActivity.java

package com.example.radioandcheckdemo;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener{

private Button button1;

private Button button2;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

button1 = (Button) findViewById(R.id.button1);

button2 = (Button) findViewById(R.id.button2);

button1.setOnClickListener(this);

button2.setOnClickListener(this);

}

@Override

public void onClick(View v) {

Intent intent = new Intent();

switch (v.getId()) {

case R.id.button1:

//跳转页面

intent.setClass(MainActivity.this, RadioActivity.class);

startActivity(intent);

break;

case R.id.button2:

//跳转页面

intent.setClass(MainActivity.this, CheckActivity.class);

startActivity(intent);

default:

break;

}

}

}

activity_radio.xml

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:id=“@+id/LinearLayout1”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

android:layout_margin=“20sp”

tools:context=“ r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}” >

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“@string/hello_world” />

<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 {

private RadioGroup group1;

private RadioGroup group2;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_radio);

group1 = (RadioGroup) findViewById(R.id.group1);

group2 = (RadioGroup) findViewById(R.id.group2);

group1.setOnCheckedChangeListener(this);

group2.setOnCheckedChangeListener(this);

}

@Override

public void onCheckedChanged(RadioGroup group, int checkedId) {

//显示值的几种方法

//checkedId选中RadioButton的id

/*switch (checkedId) {

case R.id.radio1:

Toast.makeText(this, “男”, Toast.LENGTH_LONG).show();

break;

case R.id.radio2:

Toast.makeText(this, “女”, Toast.LENGTH_LONG).show();

break;

case R.id.radio3:

Toast.makeText(this, “吃了”, Toast.LENGTH_LONG).show();

break;

case R.id.radio4:

Toast.makeText(this, “没吃”, Toast.LENGTH_LONG).show();

break;

default:

break;

}*/

//找到点击的RadioButton

//RadioButton radio = (RadioButton) findViewById(checkedId);

//取出RadioButton中的值

//String str = radio.getText().toString();

//弹框显示选中的值

//Toast.makeText(this, str, Toast.LENGTH_LONG).show();

//两组数据同时显示

//根据RadioGroup取出数据,没有选中返回-1

String str = “”;

int buttonId = group1.getCheckedRadioButtonId();

if(buttonId != -1){

RadioButton radio = (RadioButton) findViewById(buttonId);

str = “你的性别是” + radio.getText().toString();

}else{

str = “你没有选择性别”;

}

buttonId = group2.getCheckedRadioButtonId();

if(buttonId != -1){

RadioButton radio = (RadioButton) findViewById(buttonId);

str += “, 你吃饭了吗?”+radio.getText().toString();

}

Toast.makeText(this, str, Toast.LENGTH_LONG).show();

}

}

activity_check.xml

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:id=“@+id/LinearLayout1”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

tools:context=“ r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}” >

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“选择所学课程:” />

<CheckBox

android:id=“@+id/check1”
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

最后

其实Android开发的知识点就那么多,面试问来问去还是那么点东西。所以面试没有其他的诀窍,只看你对这些知识点准备的充分程度。so,出去面试时先看看自己复习到了哪个阶段就好。

虽然 Android 没有前几年火热了,已经过去了会四大组件就能找到高薪职位的时代了。这只能说明 Android 中级以下的岗位饱和了,现在高级工程师还是比较缺少的,很多高级职位给的薪资真的特别高(钱多也不一定能找到合适的),所以努力让自己成为高级工程师才是最重要的。

这里附上上述的面试题相关的几十套字节跳动,京东,小米,腾讯、头条、阿里、美团等公司21年的面试题。把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节。

由于篇幅有限,这里以图片的形式给大家展示一小部分。

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!

去面试时先看看自己复习到了哪个阶段就好。

虽然 Android 没有前几年火热了,已经过去了会四大组件就能找到高薪职位的时代了。这只能说明 Android 中级以下的岗位饱和了,现在高级工程师还是比较缺少的,很多高级职位给的薪资真的特别高(钱多也不一定能找到合适的),所以努力让自己成为高级工程师才是最重要的。

这里附上上述的面试题相关的几十套字节跳动,京东,小米,腾讯、头条、阿里、美团等公司21年的面试题。把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节。

由于篇幅有限,这里以图片的形式给大家展示一小部分。

[外链图片转存中…(img-39saVvNz-1711777374536)]

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
  • 12
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值