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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android之CheckBox复选框控件使用inelayout.xml Xml代码

發(fā)布時(shí)間:2023/12/4 Android 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android之CheckBox复选框控件使用inelayout.xml Xml代码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

linelayout.xml

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"?>??
  • ????<Button?android:layout_width="fill_parent"?android:layout_height="wrap_content"??
  • ????????android:id="@+id/buton"?android:text="@string/button">??
  • ????</Button>??
  • </LinearLayout>??
  • checkbox.xml

    Xml代碼??
  • <?xml?version="1.0"?encoding="utf-8"?>??
  • <CheckBox?xmlns:android="http://schemas.android.com/apk/res/android"??
  • ????android:layout_width="fill_parent"??
  • ????android:layout_height="wrap_content"?>??
  • </CheckBox>??
  • ?MainActivity.java

    Java代碼??
  • import?java.util.ArrayList;??
  • import?java.util.List;??
  • ??
  • import?android.app.Activity;??
  • import?android.app.AlertDialog;??
  • 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;??
  • ??
  • public?class?MainActivity?extends?Activity??implements?OnClickListener{??
  • ??
  • ????private?List?<CheckBox>?checkboxs?=?new?ArrayList<CheckBox>?();???
  • ??????
  • ????protected?void?onCreate(Bundle?savedInstanceState)?{??
  • ????????super.onCreate(savedInstanceState);??
  • ????????//setContentView(R.layout.activity_main);??
  • ????????String[]?chekcBoxTexts?=?new?String[]{"旅游","讀書","看書","爬山","踢足球","打籃球","打乒乓球"};??
  • ????????//動(dòng)態(tài)加載布局??
  • ????????LinearLayout?linerLayout?=?(LinearLayout)?getLayoutInflater().inflate(R.layout.linelayout,?null)?;??
  • ????????for(int?i=0;i<?chekcBoxTexts.length;i++){??
  • ????????????String?item?=?chekcBoxTexts[i];??
  • ????????????//動(dòng)態(tài)創(chuàng)建布局??
  • ????????????CheckBox?checkbox?=?(CheckBox)?getLayoutInflater().inflate(R.layout.checkbox,?null);??
  • ????????????checkbox.setText(item);??
  • ????????????checkboxs.add(checkbox);??
  • ??????????????
  • ????????????linerLayout.addView(checkbox,?i);??
  • ????????}??
  • ????????setContentView(linerLayout);??
  • ??????????
  • ????????Button?button?=?(Button)?this.findViewById(R.id.buton);??
  • ????????button.setOnClickListener(this)?;??
  • ????}??
  • ??
  • ????@Override??
  • ????public?void?onClick(View?v)?{??
  • ????????StringBuffer?s?=?new?StringBuffer();??
  • ????????for(CheckBox?box?:?checkboxs){??
  • ????????????if(box.isChecked()){??
  • ????????????????if(s.length()>0){s.append("\n");}??
  • ????????????????s.append(box.getText())?;??
  • ????????????}??
  • ????????}??
  • ????????if(s.length()==0){??
  • ????????????s.append("您還沒有選擇呢");??
  • ????????}??
  • ????????//使用提示框提示用戶信息??
  • ????????new?AlertDialog.Builder(this).setMessage(s.toString()).setPositiveButton("關(guān)閉",?null).show()?;??
  • ??????????
  • ????}??
  • } ?

  • 總結(jié)

    以上是生活随笔為你收集整理的Android之CheckBox复选框控件使用inelayout.xml Xml代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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