字符串资源文件strings.xml:

<resources>
<string name="hello">主类main</string>
<string name="app_name">选项</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="promptSelOK">确定</string>
<string name="hobList">你的兴趣爱好:</string>
</resources> 界面布局文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"> <CheckBox android:id="@+id/chbMusic"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/music"/>
<CheckBox android:id="@+id/chbSing"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/sing"/>
<CheckBox android:id="@+id/chbDance"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/dance"/>
<CheckBox android:id="@+id/chbTravel"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/travel"/>
<CheckBox android:id="@+id/chbReading"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/reading"/>
<CheckBox android:id="@+id/chbWriting"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/writing"/>
<CheckBox android:id="@+id/chbClimbing"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/climbing"/>
<CheckBox android:id="@+id/chbSwim"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/swim"/>
<CheckBox android:id="@+id/chbExercise"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/exercise"/>
<CheckBox android:id="@+id/chbFitness"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/fitness"/>
<CheckBox android:id="@+id/chbPhoto"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/photo"/>
<CheckBox android:id="@+id/chbEating"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/eating"/>
<CheckBox android:id="@+id/chbPainting"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/painting"/>
<Button android:id="@+id/btnSelOK"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/promptSelOK"/>
<TextView android:id="@+id/txtHobList"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/hobList"/>
</LinearLayout>
</ScrollView>
程序代码:
public class MainActivity extends Activity {

    private CheckBox chbMusic, chbSing, chbDance, chbTravel, chbReading, chbWriting, chbClimbing,
chbSwim, chbExercise, chbFitness, chbPhoto, chbEating, chbPainting; private Button btnSelOK;
private TextView txtHobList; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setupViewComponent();
} private void setupViewComponent()
{
chbMusic = (CheckBox)findViewById(R.id.chbMusic);
chbSing = (CheckBox)findViewById(R.id.chbSing);
chbDance = (CheckBox)findViewById(R.id.chbDance);
chbTravel = (CheckBox)findViewById(R.id.chbTravel);
chbReading = (CheckBox)findViewById(R.id.chbReading);
chbWriting = (CheckBox)findViewById(R.id.chbWriting);
chbClimbing = (CheckBox)findViewById(R.id.chbClimbing);
chbSwim = (CheckBox)findViewById(R.id.chbSwim);
chbExercise = (CheckBox)findViewById(R.id.chbExercise);
chbFitness = (CheckBox)findViewById(R.id.chbFitness);
chbPhoto = (CheckBox)findViewById(R.id.chbPhoto);
chbEating = (CheckBox)findViewById(R.id.chbEating);
chbPainting = (CheckBox)findViewById(R.id.chbPainting);
btnSelOK = (Button) findViewById(R.id.btnSelOK);
txtHobList = (TextView) findViewById(R.id.txtHobList); btnSelOK.setOnClickListener(btnSelOKOnClick);
} private Button.OnClickListener btnSelOKOnClick = new Button.OnClickListener()
{
public void onClick(View v)
{
String s = getString(R.string.hobList);
if(chbMusic.isChecked())
{
s += chbMusic.getText().toString();
} if(chbSing.isChecked())
{
s += chbSing.getText().toString();
} if(chbDance.isChecked())
{
s += chbDance.getText().toString();
} if(chbTravel.isChecked())
{
s += chbTravel.getText().toString();
} if(chbReading.isChecked())
{
s += chbReading.getText().toString();
} if(chbWriting.isChecked())
{
s += chbWriting.getText().toString();
} if(chbClimbing.isChecked())
{
s += chbClimbing.getText().toString();
} if(chbSwim.isChecked())
{
s += chbSwim.getText().toString();
} if(chbExercise.isChecked())
{
s += chbExercise.getText().toString();
} if(chbFitness.isChecked())
{
s += chbFitness.getText().toString();
} if(chbPhoto.isChecked())
{
s += chbPhoto.getText().toString();
} if(chbEating.isChecked())
{
s += chbEating.getText().toString();
} if(chbPainting.isChecked())
{
s += chbPainting.getText().toString();
} txtHobList.setText(s);
}
};
}
效果图:

Android入门(九):CheckBox多选清单和ScrollView滚动条的更多相关文章

  1. elementUI 学习入门之 checkbox 复选框

    CheckBox 复选框 与单选框基本类似.如:按钮样式.带边框.复选框按钮大小. eg: <template> <el-checkbox-group v-model="s ...

  2. Android入门(九)文件存储与SharedPreferences存储

    原文链接:http://www.orlion.ga/578/ Android系统中主要提供了三种方式用于简单地实现数据持久化功能,即文件存储.SharedPreference存储以及数据库存储.当然, ...

  3. Android 单选按钮(RadioButton)和复选框(CheckBox)的使用

    1.RadioButton (1)介绍 (2)单选按钮点击事件的用法 (3)RadioButton与RadioGroup配合使用实现单选题功能 (4)xml布局及使用 <?xml version ...

  4. Android基础控件单选按钮RadioButton和Checkbox复选按钮的使用

    1.相关简介 RadioButton需要和RadioGroup结合使用,在RadioGroup设置布局方式! Checkbox是单独使用,本文为了方便放在了RadioGroup中! 2.简单使用 方法 ...

  5. Android控件之CheckBox(复选框控件)

    一.有两种状态: 选中状态(true).未选中状态(false) 二.属性 android:id = "@+id/checkbox" android:layout_width=&q ...

  6. Android笔记-5-EditText密码和Checkbox二选一

    EditText密码:明文和密文 密文: public class MainActivity extends Activity { private EditText password = null; ...

  7. Android的CheckBox(多选框)

    1.布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

  8. Android中ListView结合CheckBox判断选中项

    本文主要实现在自定义的ListView布局中加入CheckBox控件,通过判断用户是否选中CheckBox来对ListView的选中项进行相应的操作.通过一个Demo来展示该功能,选中ListView ...

  9. 网络编程懒人入门(九):通俗讲解,有了IP地址,为何还要用MAC地址?

    1.前言 标题虽然是为了解释有了 IP 地址,为什么还要用 MAC 地址,但是本文的重点在于理解为什么要有 IP 这样的东西.本文对读者的定位是知道 MAC 地址是什么,IP 地址是什么. (本文同步 ...

随机推荐

  1. .net core

  2. 解决ArcGIS安装之后出现的Windows installer configures问题

    ----Please wait while Windows installer configures ArcGIS Desktop Error Message错误信息 When launching A ...

  3. Trie tree实践

    1.Trie树 Trie树即字典树或前缀树, 2.实践 代码实践如下: package cn.edu.buaa.trie; import java.util.HashSet; /** * @autho ...

  4. sql server 执行上100mb sql sql sql server 无法执行脚本 没有足够的内存继续执行

    cmd osql -S 服务器名称 -E  -i sql文件路径 ------------------------------------------------------ 最近遇到一个问题,在sq ...

  5. 学习MySQL之数据库操作(一)

    所有代码,均为自学时用到的测试与注释,知识细节或知识点不会面面俱到,亦不会有任何讲解,只做为自己学习复习用. ##数据库操作 ##创建数据库 myTest ,并将数据库字符集设为GBK CREATE ...

  6. Pandas-数据探索

    Pandas包对数据的常用探索功能,方便了解数据描述性属性. 目录 基础属性 shape indexs columns values dtype/dtypes 汇总和计算描述统计 count() va ...

  7. OpenVPN使用用户名/密码验证方式

    OpenVPN推荐使用证书进行认证,安全性很高,但是配置起来很麻烦.还好它也能像pptp等vpn一样使用用户名/密码进行认证. 不管何种认证方式,服务端的ca.crt, server.crt, ser ...

  8. 去除ios系统a标签点击时的灰色背景

    使用图片作为a标签的点击按钮时,当触发touchstart的时候,往往会有一个灰色的背景,想要去掉的话可以用下面这种方式 a,a:hover,a:active,a:visited,a:link,a:f ...

  9. 【Python基础学习四】字符串(string)

    Python 字符串 字符串是 Python 中最常用的数据类型.可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'hello' va ...

  10. jquery-简单拖拽代码

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...