这次主要是对于android中复选框的相应的操作。以及其中可能应用到的滚动条的相关应用。每一个复选框按钮都要有一个checkBox与之相对应。

推荐使用XML配置,基本语法如下:
<CheckBox
    android:text="显示文本"
    android:id="@+id/ID号"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</CheckBox>
最后添加点击事件实现相应的操作。具体的代码实现如下:

MainActivity.java

package com.example.myapplicationhome;
import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView; import org.w3c.dom.Text; public class MainActivity extends AppCompatActivity {
private CheckBox mChkBoxMusic,mChkBoxSing,mChkBoxDance,mChkBoxTravel,mChkBoxReading,mChkBoxWriting,mChkBoxFitness,mChkBoxClimbing,mChkBoxSwim,mChkBoxExercise,mChkBoxPhoto,mChkBoxEating,mChkBoxPainting;
private CheckBox mChkBoxwen1,mChkBoxwen2,mChkBoxwen3,mChkBoxwen4,mChkBoxwen5,mChkBoxwen6;
private Button mBtnOk;
private TextView mTxtHobby;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mChkBoxwen1=(CheckBox)findViewById(R.id.chkBoxwen1);
mChkBoxwen2=(CheckBox)findViewById(R.id.chkBoxwen2);
mChkBoxwen3=(CheckBox)findViewById(R.id.chkBoxwen3);
mChkBoxwen4=(CheckBox)findViewById(R.id.chkBoxwen4);
mChkBoxwen5=(CheckBox)findViewById(R.id.chkBoxwen6);
mChkBoxwen6=(CheckBox)findViewById(R.id.chkBoxwen5); mChkBoxMusic=(CheckBox)findViewById(R.id.chkBoxMusic);
mChkBoxSing=(CheckBox)findViewById(R.id.chkBoxSing);
mChkBoxDance=(CheckBox)findViewById(R.id.chkBoxDancing);
mChkBoxTravel=(CheckBox)findViewById(R.id.chkBoxTravel);
mChkBoxReading=(CheckBox)findViewById(R.id.chkBoxReading);
mChkBoxWriting=(CheckBox)findViewById(R.id.chkBoxWriting);
mChkBoxClimbing=(CheckBox)findViewById(R.id.chkBoxClimbing);
mChkBoxSwim=(CheckBox)findViewById(R.id.chkBoxSwim);
mChkBoxExercise=(CheckBox)findViewById(R.id.chkBoxExercise);
mChkBoxFitness=(CheckBox)findViewById(R.id.chkBoxFitness);
mChkBoxPhoto=(CheckBox)findViewById(R.id.chkBoxPhoto);
mChkBoxEating=(CheckBox)findViewById(R.id.chkBoxEating);
mChkBoxPainting=(CheckBox)findViewById(R.id.chkBoxPainting);
mBtnOk=(Button)findViewById(R.id.btnOk);
mTxtHobby=(TextView)findViewById(R.id.txtHobby);
mBtnOk.setOnClickListener(btnOkOnClick); }
private View.OnClickListener btnOkOnClick=new View.OnClickListener() {
@Override
public void onClick(View v) {
String s=getString(R.string.your_hobby);
if(mChkBoxMusic.isChecked())
s+=mChkBoxMusic.getText().toString();
if(mChkBoxSing.isChecked())
s+=mChkBoxSing.getText().toString();
if(mChkBoxDance.isChecked())
s+=mChkBoxDance.getText().toString();
if(mChkBoxTravel.isChecked())
s+=mChkBoxTravel.getText().toString();
if(mChkBoxReading.isChecked())
s+=mChkBoxReading.getText().toString();
if(mChkBoxWriting.isChecked())
s+=mChkBoxWriting.getText().toString();
if(mChkBoxClimbing.isChecked())
s+=mChkBoxClimbing.getText().toString();
if(mChkBoxSwim.isChecked())
s+=mChkBoxSwim.getText().toString();
if(mChkBoxExercise.isChecked())
s+=mChkBoxExercise.getText().toString();
if(mChkBoxFitness.isChecked())
s+=mChkBoxFitness.getText().toString();
if(mChkBoxPhoto.isChecked())
s+=mChkBoxPhoto.getText().toString();
if(mChkBoxEating.isChecked())
s+=mChkBoxEating.getText().toString();
if(mChkBoxPainting.isChecked())
s+=mChkBoxPainting.getText().toString(); if(mChkBoxwen1.isChecked())
s+=mChkBoxwen1.getText().toString();
if(mChkBoxwen2.isChecked())
s+=mChkBoxwen2.getText().toString();
if(mChkBoxwen3.isChecked())
s+=mChkBoxwen3.getText().toString();
if(mChkBoxwen4.isChecked())
s+=mChkBoxwen4.getText().toString();
if(mChkBoxwen5.isChecked())
s+=mChkBoxwen5.getText().toString();
if(mChkBoxwen6.isChecked())
s+=mChkBoxwen6.getText().toString(); mTxtHobby.setText(s);
}
};
}

strings.xml

<resources>
<string name="app_name">兴趣选择程序</string>
<string name="wen1">w温11</string>
<string name="wen2">w温12</string>
<string name="wen3">w温33</string>
<string name="wen4">w温44</string>
<string name="wen5">w温55</string>
<string name="wen6">w温67</string>
<string name="music">音乐</string>
<string name="sing">唱歌</string>
<string name="dance">跳舞</string>
<string name="travel">旅行</string>
<string name="reading">阅读</string>
<string name="writing">写作</string>
<string name="climbing">爬山</string>
<string name="swim">游泳</string>
<string name="exercise">运动</string>
<string name="fitness">健身</string>
<string name="photo">摄影</string>
<string name="eating">美食</string>
<string name="painting">绘画</string>
<string name="your_hobby">您的兴趣:</string>
<string name="btn_ok">确定</string>
</resources>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity"> <CheckBox
android:id="@+id/chkBoxwen6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/wen6" />
<CheckBox
android:id="@+id/chkBoxwen5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/wen5" />
<CheckBox
android:id="@+id/chkBoxwen4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/wen4" />
<CheckBox
android:id="@+id/chkBoxwen3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/wen3" />
<CheckBox
android:id="@+id/chkBoxwen2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/wen2" />
<CheckBox
android:id="@+id/chkBoxwen1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/wen1" />
<CheckBox
android:id="@+id/chkBoxMusic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/music" />
<CheckBox
android:id="@+id/chkBoxSing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/sing" />
<CheckBox
android:id="@+id/chkBoxDancing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/dance" />
<CheckBox
android:id="@+id/chkBoxTravel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/travel" />
<CheckBox
android:id="@+id/chkBoxReading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/reading" />
<CheckBox
android:id="@+id/chkBoxWriting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/writing" />
<CheckBox
android:id="@+id/chkBoxClimbing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/climbing" />
<CheckBox
android:id="@+id/chkBoxSwim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/swim" /> <CheckBox
android:id="@+id/chkBoxExercise"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/exercise"
android:textSize="30sp" />
<CheckBox
android:id="@+id/chkBoxFitness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/fitness" />
<CheckBox
android:id="@+id/chkBoxPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/photo" />
<CheckBox
android:id="@+id/chkBoxEating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/eating" />
<CheckBox
android:id="@+id/chkBoxPainting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/painting" /> <Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_ok" /> <TextView
android:id="@+id/txtHobby"
android:layout_width="420dp"
android:layout_height="47dp" />
</LinearLayout> </ScrollView>

选出几个兴趣之后。点击确定按钮的显示结果:

家庭记账本app进度之复选框以及相应滚动条的应用的更多相关文章

  1. 家庭记账本app进度之android中AlertDialog的相关应用以及对日期时间的相关操作(应用alertdialog使用的谈话框)

    对于AlertDialog的相关知识: 1.创建构造器AlertDialog.Builder的对象:    2.通过构造器对象调用setTitle.setMessage.setIcon等方法构造对话框 ...

  2. 家庭记账本app进度之对于登录和注册两个界面点击按钮的相互跳转

    这次主要完成了两个两个android页面之间的跳转.从登录页面点击注册就会跳转到注册页面.在注册页面点击返回登录,这样就可以返回到登录界面.主要是这样的操作.其中遇到了一个困难主要是当点击按钮的时候, ...

  3. 家庭记账本app进度之下拉框和数字转轮的相关应用

    这次主要是悬系的下拉框Spinner和数字转轮NumberPicker的使用.先分析相关的用到的知识点. 在Android中,用string-array是一种简单的提取XML资源文件数据的方法. 例子 ...

  4. 家庭记账本app进度之关于单选按钮的相关操作(添加点击按钮事件以及点击单选更改事件)

    这次主要是通过代码实现了android中的相关单选按钮的相关操作,之后再最下面有一个按钮,当点击这个按钮的时候,会获取当上面的相关信息,之后再下方会进行相应的文字显示,获取的信息不同显示的信息也不会一 ...

  5. 家庭记账本app进度之关于tap的相关操作1

    今天还主要学习关于怎样制作微信的先关的tap. 今天的主要成果是已经了解了相关的技术,以及相关的思路.代码经过一个下午的编写,基本接近尾声. 更详细的实验代码,以及相关的知识点将在明天完善后进行发表. ...

  6. 家庭记账本app进度之ui相关概念控制ui界面与布局管理

    ui就是用户界面设计的意思. 首先是view,view相当于窗户上的玻璃. 1.android:id属性.android:id="@+id/user".他的id是user前面的@+ ...

  7. 进度1_家庭记账本App

    今天完成了昨天的初步构想,详细介绍见上一篇博客,具体项目结构和案例如下: MainActivity.java: package com.example.familybooks; import andr ...

  8. 家庭记账本APP开发准备(三)

    单选框(RadioButton) 通过设置单选框,可以将非此即彼的问题进行解决,成功学会并应用了手机端单项选择框; 复选框(CheckBox) 学习复选框是为了给使用软件的人更多的选择,在其他选择框后 ...

  9. 进度4_家庭记账本App

    在上一个博客中,我学习了用Fragment进行数据的传值,但是出现了好多问题,我通过百度查阅资料发现fregment在进行数值传输的时候有的语法不能使用,并且不方便的进行数据库的使用,所以我在原来的家 ...

随机推荐

  1. Java反射之成员方法的反射

    上一篇介绍了Java反射之成员变量的反射,这次介绍成员方法的反射. [一]Method类 Method类中封装了所有java方法的属性,包括该方法是否私有,该方法的修饰符,返回值,参数,抛的错误等等. ...

  2. 5W2H方法:七问分析法

    5W2H分析方法也叫七问分析法,是二战中美国陆军兵器修理部首创.简单.方便.易于理解.使用,富有启发意义,被广泛应用于企业管理和技术活动,对于决策和执行性的措施也非常有帮助,有助于弥补考虑问题的疏漏. ...

  3. OFD电子证照模版制作工具 --(采用wpf开发)

    前言  ofd应用的范围非常广,电子证照是其中非常重要的一个应用.同一类电子证照具有相同的板式.元数据:所以电子证照非常适合用模版来制作.模版就是板式样式固定,每个具体的证照只是文字或图片内容不同.比 ...

  4. Nodejs:md5入门介绍及crypto模块的应用

    简介 MD5(Message-Digest Algorithm)是计算机安全领域广泛使用的散列函数(又称哈希算法.摘要算法),主要用来确保消息的完整和一致性.常见的应用场景有密码保护.下载文件校验等. ...

  5. mysql schema设计中应避免的陷阱

    谨记红字: 1. 表中谨防太多列: MySQL 的存储引擎API 工作时需要在服务器层和存储引擎层之间通过行缓冲格式拷贝数据,然后在服务器层将缓冲内容解码成各个列.从行缓冲中将编码过的列转换成行数据结 ...

  6. js获取按钮的文字

    button按钮有两种情况: 1 <input type="button" id="button" value="button"> ...

  7. EPX Studio开发环境介绍

    相信用过Delphi的人,都很清楚FastScript,EPX Studio就是以FastScript为编程基础语言,由于FastScript支持类似于Delphi的Pascal语法,因此EPX St ...

  8. VS2019 C++动态链接库的创建使用(2) - 客户调用接口

    因为动态链接库里的内容是自己定义的,所以在外部程序调用时我们自己知道库里包含哪些变量和函数,如果我们提供库给其他人使用,则最好增加一个头文件,告知库里包含的函数: ①将动态链接库源文件内容增加红色框内 ...

  9. 洛谷1378 油滴扩展 dfs进行回溯搜索

    题目链接:https://www.luogu.com.cn/problem/P1378 题目中给出矩形的长宽和一些点,可以在每个点放油滴,油滴会扩展,直到触碰到矩形的周边或者其他油滴的边缘,求出剩余面 ...

  10. CF1324D Pair of Topics 题解

    原题链接 简要题意: 有两个数组 \(a_i\),\(b_i\),求有多少组 \(a_i + a_j > b_i + b_j (i \not = j)\). 显然,纯暴力过不了这道题目. 首先, ...