在main.xml中

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

android:id="@+id/mych"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text=""/>

<Button

android:id="@+id/mybut"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

        android:text="请选择水果"/>

</LinearLayout>

在MyDialogDemo.java程序中

package com.tarena.dialog;

import android.app.Activity;

import android.app.AlertDialog;

import android.app.Dialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageButton;

import android.widget.TextView;

public class MyDialogDemo extends Activity {

private Button mybut = null ; // 定义按钮

private TextView mych = null ; // 定义文本

private TextView mytext = null ; // 定义文本

private String fruitData [] = new String[] { "苹果", "西瓜", "水蜜桃" };

private boolean chData[] = new boolean[]{false,false,false};

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.setContentView(R.layout.main); // 调用布局管理器

this.mybut = (Button) super.findViewById(R.id.mybut) ;  // 取得按钮

this.mych = (TextView) super.findViewById(R.id.mych) ;  // 取得文本

this.mybut.setOnClickListener(new OnClickListenerImpl()) ;  // 设置事件类

}

private class OnClickListenerImpl implements OnClickListener {

public void onClick(View view) {

Dialog dialog = new AlertDialog.Builder(MyDialogDemo.this)

.setIcon(R.drawable.ic_launcher)

.setTitle("请选择你喜欢吃的水果?")

.setPositiveButton("确定", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

})

.setNegativeButton("取消", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

}).setMultiChoiceItems(MyDialogDemo.this.fruitData,

MyDialogDemo.this.chData, new DialogInterface

.OnMultiChoiceClickListener() {

public void onClick(DialogInterface dialog, int which, boolean isChecked) {

for(int x = 0; x < MyDialogDemo.this.fruitData.length; x++){

if(x == which && isChecked){  //被选中

MyDialogDemo.this.mych.append(MyDialogDemo.this.fruitData[x] + "\n");

}

}

}

}).create() ;

dialog.show() ;

}

}

}

android 多项对话框的更多相关文章

  1. Android 自学之对话框

    Android为我们提供了丰富的对话框支持,提供了四种常用的对话框: AlertDialog:功能丰富.实际应用最广泛的对话框. ProgressDialog:进度对话框,该对话框只用于简单的进度条封 ...

  2. Android中的对话框AlertDialog使用技巧合集-转载

    Android中的对话框AlertDialog使用技巧合集     文章来自:http://blog.csdn.net/blue6626/article/details/6641105   今天我用自 ...

  3. 9.Android之日期对话框DatePicker控件学习

    设置日期对话框在手机经常用到,今天来学习下. 首先设置好布局文件:如图 xml对应代码 <?xml version="1.0" encoding="utf-8&qu ...

  4. Android:AlertDialog对话框

    1.简单的ALertDialog: Dialog alertDialog = new AlertDialog.Builder(this) .setTitle("标题") .setM ...

  5. Android中Dialog对话框

    布局文件xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...

  6. Android中弹出对话框,AlertDialog关键代码

    写在这里便于以后查看. Android中弹出对话框的关键代码: btn01.setOnClickListener(new OnClickListener() { @Override public vo ...

  7. Android UI系列--对话框(一)(AlertDialog,TimePickerDialog,DatePickerDialog,ProgressDialog)

    一.Dialog介绍 dialog就是一个在屏幕上弹出一个可以让用户做出一个选择,或者输入额外的信息的对话框,一个对话框并不会沾满我们整个的屏幕,并且通常用于模型事件当中需要用户做出一个决定后才会继续 ...

  8. Android开发之对话框高级应用

    Android开发之对话框高级应用 创建并显示一个对话框非常easy.可是假设想进行一些更高级点的操作,就须要一些技巧了.以下将和大家分享一下对话框使用的一些高级技巧. 1.改变对话框的显示位置: 大 ...

  9. android从Dialog对话框中取得文本文字

    android中Dialog对话框获取文本文字,只需要使用editor的getText方法就可以获得,示例如下:final EditText et = new EditText(this); et.s ...

随机推荐

  1. Android弹性ScrollView

    开袋即食 import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; ...

  2. 如何解决Windows 7的多重网络问题

    如何解决Windows 7的多重网络问题   出现这种现象一般是明天网络还好好的,今天一开机就上不了网了,可是局域网是通的.打开网络和共享中心你会发现PC和Internet之间是一个多重网络.造成这种 ...

  3. iOS-封装静态库

    最近在做Apple的IOS开发,有开发静态库的需求,本身IOS的开发,只允许静态库或者Framework.在Xcode上没有找到允许编译,如同Android上的*.so和Win32上的dll这样的说法 ...

  4. ASP.NET c#学习经验

    1.DataGrid自定义字段.<Column  <asp:BoundColumn DataField="khbh" HeaderText="客户编号&quo ...

  5. Qt5-控件-QRadioButton-单选按钮-用于从多个选项中选取一个-单选神器

    #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QRadioButton> ...

  6. Java学习笔记——实现一个简易记事本Notepad的编写

    记事本功能介绍 1.   新建:记事本清空. 2.   打开:可打开笔记本上任意文本文件. 3.   保存:将文件保存至当前文件夹. 4.   另存为:将文件保存至任意位置. 5.   退出:退出时确 ...

  7. Linux 从 sar 到 sar2html 的认识

    这些变形的工具.诸如:淘宝的Tsar.ksar.sar2html....等.都是通过抓取 sar的数据   所以在最终呈现的数据上变化不大.只是展现的手段和效果不一样而已      sar 是帮助我们 ...

  8. js 跨浏览操作

    /* 跨浏览器添加事件绑定  obj : 需要绑定js时间的对象 type:  欲绑定的事件类型,如:click ,mounseover 等事件  不需要添加on fn  :  触发的脚本*/func ...

  9. jquery判断滚动条到底

    $(document).scroll(function(){ var dHeight = $(document).height(); var wHeight = $(window).height(); ...

  10. C 中typedef 函数指针的使用

    类型定义的语法可以归结为一句话:只要在变量定义前面加上typedef,就成了类型定义.这儿的原本应该是变量的东西,就成为了类型. int integer;     //整型变量int *pointer ...