CheckBox复选框控件使用方法,具体内容如下

一、简介

1、

2、类结构图

二、CheckBox复选框控件使用方法

这里是使用java代码在LinearLayout里面添加控件

1、新建LinearLayout布局

2、建立CheckBox的XML的Layout文件

3、通过View.inflate()方法创建CheckBox

CheckBox checkBox=(CheckBox) View.inflate(this, R.layout.checkbox, null);

4、通过LinearLayout的addView方法添加CheckBox

ll_checkBoxList.addView(checkBox);

5、通过List完成输出功能

for(CheckBox checkBox:checkBoxList)

三、代码实例

1、效果图:

2、代码

fry.Activity01

package fry;

import java.util.ArrayList;

import java.util.List;

import com.example.CheckBoxDemo1.R;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.LinearLayout;

import android.widget.Toast;

public class Activity01 extends Activity implements OnClickListener{

private List checkBoxList=new ArrayList();

private LinearLayout ll_checkBoxList;

private Button btn_ok;

// CheckBox复选框控件使用方法

// 这里是使用java代码在LinearLayout里面添加控件

// 1、新建LinearLayout布局

// 2、建立CheckBox的XML的Layout文件

// 3、通过View.inflate()方法创建CheckBox

// 4、通过LinearLayout的addView方法添加CheckBox

// 5、通过List完成输出功能

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.activity01);

ll_checkBoxList=(LinearLayout) findViewById(R.id.ll_CheckBoxList);

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

String[] strArr={"你是学生吗?","你是否喜欢android","您喜欢旅游吗?","打算出国吗?"};

for(String str:strArr){

CheckBox checkBox=(CheckBox) View.inflate(this, R.layout.checkbox, null);

checkBox.setText(str);

ll_checkBoxList.addView(checkBox);

checkBoxList.add(checkBox);

}

btn_ok.setOnClickListener(this);

}

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

String str="";

for(CheckBox checkBox:checkBoxList){

if(checkBox.isChecked()){

str+=checkBox.getText().toString()+"\n";

}

}

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

}

}

/CheckBoxDemo1/res/layout/activity01.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@+id/ll_CheckBoxList"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

android:id="@+id/btn_ok"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="确定"

/>

/CheckBoxDemo1/res/layout/checkbox.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

四、收获

1、 View.inflate(this, R.layout.checkbox, null)方法里面的checkbox的XML

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

2、用代码在LinearLayout中添加CheckBox方法

1)通过View.inflate()方法创建CheckBox

CheckBox checkBox=(CheckBox) View.inflate(this, R.layout.checkbox, null);

2)通过LinearLayout的addView方法添加CheckBox

ll_checkBoxList.addView(checkBox);

3、List的创建

private List checkBoxList=new ArrayList();

4、for(CheckBox checkBox:checkBoxList)

遍历

5、list类结构图

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

android勾选控件_Android中CheckBox复选框控件使用方法详解相关推荐

  1. python反向缩进_在Pycharm中对代码进行注释和缩进的方法详解

    在Pycharm中对代码进行注释和缩进的方法详解 一.注释 1. #单行注释 2. """ 多行注释 """ 3. pycharm多行注释快 ...

  2. python 读取图片转换为一维向量_对Python中一维向量和一维向量转置相乘的方法详解...

    对Python中一维向量和一维向量转置相乘的方法详解 在Python中有时会碰到需要一个一维列向量(n*1)与另一个一维列向量(n*1)的转置(1*n)相乘,得到一个n*n的矩阵的情况.但是在pyth ...

  3. python二维元组_python中读入二维csv格式的表格方法详解(以元组/列表形式表示)

    如何去读取一个没有表头的二维csv文件(如下图所示)? 并以元组的形式表现数据: ((1.0, 0.0, 3.0, 180.0), (2.0, 0.0, 2.0, 180.0), (3.0, 0.0, ...

  4. python可以使用二维元组吗_python中读入二维csv格式的表格方法详解(以元组/列表形式表示)...

    怎么去读取一个没有表头的二维csv文件(如下图所示)? 并以元组的形式表现数据: ((1.0, 0.0, 3.0, 180.0), (2.0, 0.0, 2.0, 180.0), (3.0, 0.0, ...

  5. python元组读取到列表_python中读入二维csv格式的表格方法详解(以元组/列表形式表示)...

    如何去读取一个没有表头的二维csv文件(如下图所示)? 并以元组的形式表现数据: ((1.0, 0.0, 3.0, 180.0), (2.0, 0.0, 2.0, 180.0), (3.0, 0.0, ...

  6. thinkphp3.1.3 getshell_C# / VB.NET 在PPT中创建、编辑PPT SmartArt图形的方法详解_C#教程...

    本文介绍通过C#和程序代码来创建和编辑PPT文档中的SmartArt图形.文中将分两个操作示例来演示创建和编辑结果. 使用工具:Spire.Presentation for .NET hotfix 5 ...

  7. python读二进制格点雷达基数据_对numpy中二进制格式的数据存储与读取方法详解...

    使用save可以实现对numpy数据的磁盘存储,存储的方式是二进制.查看使用说明,说明专门提到了是未经压缩的二进制形式.存储后的数据可以进行加载或者读取,通过使用load方法. In [81]:np. ...

  8. uniapp中checkbox复选框动态绑定数据

    checkbox复选框动态绑定数据: <template><view class="box"><checkbox-group @change=&quo ...

  9. php表单复选传值,jQuery+SpringMVC中的复选框选择与传值实例_jquery

    下面我就为大家分享一篇jQuery+SpringMVC中的复选框选择与传值实例,具有很好的参考价值,希望对大家有所帮助. 一.checkbox选择 在jQuery中,选中checkbox通用的两种方式 ...

最新文章

  1. 点分治问题 ----------- luoguP2942 [WC2010]重建计划 [点分治 + bfs + 单调队列 + 预处理建树 + 二分 + 01分数规划]
  2. Lucene:基于Java的全文检索引擎简介 车东
  3. 英特尔是 Chrome OS 代码的第二大贡献者
  4. python bottle学习(四)request.quest/query_string/params/body等方法介绍
  5. Objectice-C之类层次结构
  6. 很好的大数据名词解释,收藏
  7. asp手机拍照显示_会员动态飞凯材料120吨TFTLCD混合液晶显示项目,建后五年达产...
  8. aix系统java堆_浅谈AIX环境下的Java性能调优
  9. mysql 替换非中文_mysql中的正则操作 匹配手机号,匹配中文,替换
  10. 高中生用付款截图吃霸王餐近一年 网友:支付宝进来推销
  11. jquery项目中一些常用方法
  12. 七、制作主题(二) Anatomy of a theme
  13. OpenCV-美食—鲜美滤镜
  14. LuckyFrame执行Web自动化用例
  15. 保存画面为图片 当前MFC保存该程序为图片 c++ vc
  16. C++ 从入门到入土(English Version)Section3: Real numbers + bitwise operations
  17. 【CRC】CRC推导(二)模二除法
  18. java排球计分表窗口_排球计分程序(五)—— Controller的设计与实现
  19. 【九】【vlc-android】vlc-aout音频流输出端源码分析
  20. 定义char dog[]=wang\0miao;那么sizeof(dog)与strlen(dog)分别是多少:

热门文章

  1. python 求厉害数
  2. php数组地址,怎么实现javascript数组与php数组的地址传递
  3. jupyter 数据分析可视化案例_Python数据分析及可视化实例之Anaconda、Jupyter简介
  4. C语言程序练习- L1-040 最佳情侣身高差 (10分)
  5. 每日程序C语言39-不带头结点的头插法创建链表
  6. Unity性能优化-遮挡剔除
  7. 解题:USACO15JAN Grass Cownoisseur
  8. Linux 基础学习大考核
  9. python——数据类型
  10. Ubuntu下的第一个博客