最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中CheckBox復(fù)選框控件使用方法詳解

 更新時(shí)間:2017年08月07日 11:32:08   作者:飯飯_fan  
這篇文章主要為大家詳細(xì)介紹了Android中CheckBox復(fù)選框控件的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

CheckBox復(fù)選框控件使用方法,具體內(nèi)容如下

一、簡(jiǎn)介

1、

2、類(lèi)結(jié)構(gòu)圖

二、CheckBox復(fù)選框控件使用方法

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

1、新建LinearLayout布局

2、建立CheckBox的XML的Layout文件

3、通過(guò)View.inflate()方法創(chuàng)建CheckBox

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

4、通過(guò)LinearLayout的addView方法添加CheckBox

ll_checkBoxList.addView(checkBox); 

5、通過(guò)List<CheckBox>完成輸出功能

for(CheckBox checkBox:checkBoxList) 

三、代碼實(shí)例

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<CheckBox> checkBoxList=new ArrayList<CheckBox>();
  private LinearLayout ll_checkBoxList;
  private Button btn_ok;
//  CheckBox復(fù)選框控件使用方法
//  這里是使用java代碼在LinearLayout里面添加控件
//  1、新建LinearLayout布局
//  2、建立CheckBox的XML的Layout文件
//  3、通過(guò)View.inflate()方法創(chuàng)建CheckBox
//  4、通過(guò)LinearLayout的addView方法添加CheckBox
//  5、通過(guò)List<CheckBox>完成輸出功能
  @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={"你是學(xué)生嗎?","你是否喜歡android","您喜歡旅游嗎?","打算出國(guó)嗎?"};
    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

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

  <LinearLayout 
    android:id="@+id/ll_CheckBoxList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
    
    
  </LinearLayout>
  
  <Button 
    android:id="@+id/btn_ok"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="確定"
    />
  
  
</LinearLayout>

/CheckBoxDemo1/res/layout/checkbox.xml

<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >


</CheckBox>

四、收獲

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

<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
</CheckBox>

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

1)通過(guò)View.inflate()方法創(chuàng)建CheckBox

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

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

ll_checkBoxList.addView(checkBox);

3、List<CheckBox>的創(chuàng)建

private List<CheckBox> checkBoxList=new ArrayList<CheckBox>();

4、for(CheckBox checkBox:checkBoxList)

遍歷

5、list類(lèi)結(jié)構(gòu)圖

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android事件總線EventBus3.0使用方法詳解

    android事件總線EventBus3.0使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了android事件總線EventBus3.0使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android筆記之:在ScrollView中嵌套ListView的方法

    Android筆記之:在ScrollView中嵌套ListView的方法

    本篇文章是對(duì)Android中在ScrollView中嵌套ListView的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Android Studio設(shè)置顏色拾色器工具Color Picker教程

    Android Studio設(shè)置顏色拾色器工具Color Picker教程

    這篇文章主要介紹了Android Studio設(shè)置顏色拾色器工具Color Picker教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • Android中ListView使用示例介紹

    Android中ListView使用示例介紹

    大家好,本篇文章主要講的是Android中ListView使用示例介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話(huà)記得收藏一下,方便下次瀏覽
    2022-01-01
  • 解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問(wèn)題

    解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問(wèn)題

    今天小編就為大家分享一篇解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • Android uses-permission權(quán)限列表中文注釋版

    Android uses-permission權(quán)限列表中文注釋版

    Android有一個(gè)精心設(shè)計(jì)的安全模型。每一個(gè)應(yīng)用都有其自己Linux用戶(hù)和群組,在單獨(dú)的進(jìn)程和VM上運(yùn)行,不能影響到其他應(yīng)用
    2014-05-05
  • Android使用AlertDialog創(chuàng)建對(duì)話(huà)框

    Android使用AlertDialog創(chuàng)建對(duì)話(huà)框

    這篇文章主要為大家詳細(xì)介紹了Android使用AlertDialog創(chuàng)建對(duì)話(huà)框的方法料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android實(shí)現(xiàn)簡(jiǎn)單的自定義ViewGroup流式布局

    Android實(shí)現(xiàn)簡(jiǎn)單的自定義ViewGroup流式布局

    本文我們將一起復(fù)習(xí)一下ViewGroup的測(cè)量布局方式。然后會(huì)以入門(mén)級(jí)的 FlowLayout 為例,來(lái)看看流式布局是如何測(cè)量與布局的,感興趣的可以了解一下
    2022-12-12
  • 谷歌被屏蔽后如何搭建安卓環(huán)境

    谷歌被屏蔽后如何搭建安卓環(huán)境

    從5月27日開(kāi)始,谷歌(Google)在華的幾乎所有的服務(wù)都處于無(wú)法使用的狀態(tài),除了搜索引擎遭到屏蔽之外,谷歌的郵箱(Gmail)、日歷(Calendar)、翻譯(Translate)、地圖(Maps)、分析(Analytics)和Google AdSense等產(chǎn)品也受到了影響。同時(shí)安裝安卓環(huán)境的時(shí)候同樣容易出現(xiàn)問(wèn)題
    2014-06-06
  • kotlin android extensions 插件實(shí)現(xiàn)示例詳解

    kotlin android extensions 插件實(shí)現(xiàn)示例詳解

    這篇文章主要為大家介紹了kotlin android extensions 插件實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10

最新評(píng)論

绩溪县| 安阳市| 佛冈县| 内丘县| 柳林县| 浦东新区| 灵宝市| 黄冈市| 中牟县| 合阳县| 赫章县| 辛集市| 胶州市| 石渠县| 阿克陶县| 漠河县| 盈江县| 如皋市| 临湘市| 治多县| 花垣县| 合阳县| 湘潭市| 华池县| 杭锦后旗| 疏勒县| 平湖市| 瑞安市| 宁德市| 应城市| 汉川市| 兰溪市| 沿河| 拜泉县| 贡嘎县| 博爱县| 井陉县| 丰顺县| 航空| 延庆县| 年辖:市辖区|