Android——单选多选按钮的使用详解,作为一名android面试者你应该知道的问题

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

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

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

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注Android)
img

正文

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”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“HTML” />

<CheckBox

android:id=“@+id/check2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

文末

那么对于想坚持程序员这行的真的就一点希望都没有吗?
其实不然,在互联网的大浪淘沙之下,留下的永远是最优秀的,我们考虑的不是哪个行业差哪个行业难,就逃避掉这些,无论哪个行业,都会有他的问题,但是无论哪个行业都会有站在最顶端的那群人。我们要做的就是努力提升自己,让自己站在最顶端,学历不够那就去读,知识不够那就去学。人之所以为人,不就是有解决问题的能力吗?挡住自己的由于只有自己。
Android希望=技能+面试

  • 技能
  • 面试技巧+面试题

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注Android)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

不是哪个行业差哪个行业难,就逃避掉这些,无论哪个行业,都会有他的问题,但是无论哪个行业都会有站在最顶端的那群人。我们要做的就是努力提升自己,让自己站在最顶端,学历不够那就去读,知识不够那就去学。人之所以为人,不就是有解决问题的能力吗?挡住自己的由于只有自己。
Android希望=技能+面试

  • 技能
    [外链图片转存中…(img-fU3FjgWn-1713702756802)]
  • 面试技巧+面试题
    [外链图片转存中…(img-XrWqKVbV-1713702756802)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注Android)
[外链图片转存中…(img-dE8froFe-1713702756803)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 17
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值