资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Android中CheckBox复选框控件使用方法详解-创新互联

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

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都做网站、外贸网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的东湖网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

一、简介

1、

2、类结构图

Android中CheckBox复选框控件使用方法详解

二、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();
  }
}

网站栏目:Android中CheckBox复选框控件使用方法详解-创新互联
URL网址:http://cdkjz.cn/article/ddpses.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220