Android之復(fù)選框?qū)υ捒蛴梅▽?shí)例分析
本文實(shí)例講述了Android之復(fù)選框?qū)υ捒蛴梅ā7窒斫o大家供大家參考。具體如下:
main.xml布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <EditText android:text="" android:id="@+id/editText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:editable="false" android:cursorVisible="false" /> <Button android:text="顯示復(fù)選框?qū)υ捒? android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
array.xml數(shù)組
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="hobby"> <item>游泳</item> <item>打籃球</item> <item>登山</item> </string-array> </resources>
AlertActivity類
package com.ljq.dialog; import android.app.Activity; import android.app.Dialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class AlertDialog extends Activity { private EditText editText; private final static int DIALOG=1; boolean[] flags=new boolean[]{false,false,false};//初始復(fù)選情況 String[] items=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); items=getResources().getStringArray(R.array.hobby); editText=(EditText)findViewById(R.id.editText); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // 顯示對(duì)話框 showDialog(DIALOG); } }); } /** * 創(chuàng)建復(fù)選框?qū)υ捒? */ @Override protected Dialog onCreateDialog(int id) { Dialog dialog=null; switch (id) { case DIALOG: Builder builder=new android.app.AlertDialog.Builder(this); //設(shè)置對(duì)話框的圖標(biāo) builder.setIcon(R.drawable.header); //設(shè)置對(duì)話框的標(biāo)題 builder.setTitle("復(fù)選框?qū)υ捒?); builder.setMultiChoiceItems(R.array.hobby, flags, new DialogInterface.OnMultiChoiceClickListener(){ public void onClick(DialogInterface dialog, int which, boolean isChecked) { flags[which]=isChecked; String result = "您選擇了:"; for (int i = 0; i < flags.length; i++) { if(flags[i]){ result=result+items[i]+"、"; } } editText.setText(result.substring(0, result.length()-1)); } }); //添加一個(gè)確定按鈕 builder.setPositiveButton(" 確 定 ", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int which) { } }); //創(chuàng)建一個(gè)復(fù)選框?qū)υ捒? dialog=builder.create(); break; } return dialog; } }
運(yùn)行結(jié)果:
希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android RadioButton單選框的使用方法
- Android程序開發(fā)中單選按鈕(RadioGroup)的使用詳解
- Android中創(chuàng)建對(duì)話框(確定取消對(duì)話框、單選對(duì)話框、多選對(duì)話框)實(shí)例代碼
- Android自定義單選多選下拉列表的實(shí)例代碼
- Android單選按鈕對(duì)話框用法實(shí)例分析
- android實(shí)現(xiàn)單選按鈕功能
- Android ListView實(shí)現(xiàn)單選及多選等功能示例
- Android中CheckBox復(fù)選框控件使用方法詳解
- Android復(fù)選框?qū)υ捒蛴梅▽?shí)例簡(jiǎn)析
- Android開發(fā)之獲取單選與復(fù)選框的值操作示例
相關(guān)文章
Android中截取當(dāng)前屏幕圖片的實(shí)例代碼
該篇文章是說明在Android手機(jī)或平板電腦中如何實(shí)現(xiàn)截取當(dāng)前屏幕的功能,并把截取的屏幕保存到SDCard中的某個(gè)目錄文件夾下面。實(shí)現(xiàn)的代碼如下:2013-08-08Android 自動(dòng)化測(cè)試經(jīng)驗(yàn)分享 UiObejct.getFromParent()的使用方法
本篇文章對(duì)Android中UiObejct.getFromParent()的使用進(jìn)行了詳細(xì)的分析介紹。需要的朋友參考下2013-05-05Android TimerTask 的簡(jiǎn)單應(yīng)用及注意事項(xiàng)
這篇文章主要介紹了Android TimerTask 的簡(jiǎn)單應(yīng)用及注意事項(xiàng)的相關(guān)資料,需要的朋友可以參考下2017-06-06Android中Glide實(shí)現(xiàn)超簡(jiǎn)單的圖片下載功能
本篇文章主要介紹了Android中Glide實(shí)現(xiàn)超簡(jiǎn)單的圖片下載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03Android布局自定義Shap圓形ImageView可以單獨(dú)設(shè)置背景與圖片
這篇文章主要介紹了Android布局自定義Shap圓形ImageView可以單獨(dú)設(shè)置背景與圖片 的相關(guān)資料,需要的朋友可以參考下2016-01-01Android startActivityForResult實(shí)例詳解
這篇文章主要介紹了Android startActivityForResult實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05自定義Toast工具類ToastUtil防止多次點(diǎn)擊時(shí)Toast不消失的方法
下面小編就為大家?guī)硪黄远xToast工具類ToastUtil防止多次點(diǎn)擊時(shí)Toast不消失的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04