字符串资源文件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. Windows远程数据同步工具cwRsync

    1. cwRsync简介cwRsync是Rsync在Windows上的实现版本,Rsync通过使用特定算法的文件传输技术,可以在网络上传输只修改了的文件.cwRsync主要用于Windows上的远程文 ...

  2. NOSDK--一键打包的实现(二)

    Android.mk文件,位置在android工程/jni目录下,是android工程中的makefile文件,这里我们简称它为mk文件. 1.2 自动刷新mk文件的脚本介绍 这一节介绍mk文件的自动 ...

  3. 个性化设置phpMyAdmin,去掉“以树形显示数据库”,禁用“发送错误报告”

    个性化设置phpMyAdmin 在使用phpMyAdmin 3.5.8.2时,发现: 如果数据库有相同的前缀,左边数据库导航会把前缀合并,即所谓的“以树形显示数据库”,真的有点不习惯,如下图所示: 不 ...

  4. 父类方法返回子类实例:PHP延迟静态绑定

    案例分析 先前的PHP项目中,看到类似于以下的一段代码: <?php class DBHandler { public function get() { } } class MySQLHandl ...

  5. 关于DataTable添加新列到指定列的方法

    在开发新项目的时候发现了一个问题 dtResult.Columns.Add()方法只能将指定的列添加到DataTable的列的最后的位置,但是不能添加到指定的列上.举例来说,假设dtResult总共有 ...

  6. 第2月第5天 arc invocation getReturnValue

    http://blog.csdn.net/zengconggen/article/details/38024625

  7. bzoj3551 Peaks加强版

    这个题--感觉离线和在线的代码难度差不多(pb_ds不要说话). 离线的话,就是把所有询问按照w排个序,然后一边Kruskal+平衡树启发式合并一边回答询问就好了. 在线也不难写.首先Kruskal重 ...

  8. 【转】ubuntu 配置 java jdk1.8 环境,增加多版本 jdk 和切换方法

    一.安装java jdk1.8 1.添加软件源 sudo add-apt-repository ppa:webupd8team/java 2.更新软件源 sudo apt-get update 3.安 ...

  9. at 常用命令

    以debian 6.0.1 为例: 服务开启关闭: Usage: /etc/init.d/atd {start|stop|restart|force-reload|status} 设置一次计划任务(a ...

  10. Linux IO模式及 select、poll、epoll详解

    linux的IO调度文章==> https://segmentfault.com/a/1190000003063859?hmsr=toutiao.io&utm_medium=toutia ...