日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發(fā)布時間:2024/4/19 Android 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android勾选控件_Android中CheckBox复选框控件使用方法详解 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

CheckBox復選框控件使用方法,具體內容如下

一、簡介

1、

2、類結構圖

二、CheckBox復選框控件使用方法

這里是使用java代碼在LinearLayout里面添加控件

1、新建LinearLayout布局

2、建立CheckBox的XML的Layout文件

3、通過View.inflate()方法創(chuàng)建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()方法創(chuàng)建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()方法創(chuàng)建CheckBox

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

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

ll_checkBoxList.addView(checkBox);

3、List的創(chuàng)建

private List checkBoxList=new ArrayList();

4、for(CheckBox checkBox:checkBoxList)

遍歷

5、list類結構圖

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的android勾选控件_Android中CheckBox复选框控件使用方法详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。