android 多项对话框
在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 多项对话框的更多相关文章
- Android 自学之对话框
Android为我们提供了丰富的对话框支持,提供了四种常用的对话框: AlertDialog:功能丰富.实际应用最广泛的对话框. ProgressDialog:进度对话框,该对话框只用于简单的进度条封 ...
- Android中的对话框AlertDialog使用技巧合集-转载
Android中的对话框AlertDialog使用技巧合集 文章来自:http://blog.csdn.net/blue6626/article/details/6641105 今天我用自 ...
- 9.Android之日期对话框DatePicker控件学习
设置日期对话框在手机经常用到,今天来学习下. 首先设置好布局文件:如图 xml对应代码 <?xml version="1.0" encoding="utf-8&qu ...
- Android:AlertDialog对话框
1.简单的ALertDialog: Dialog alertDialog = new AlertDialog.Builder(this) .setTitle("标题") .setM ...
- Android中Dialog对话框
布局文件xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
- Android中弹出对话框,AlertDialog关键代码
写在这里便于以后查看. Android中弹出对话框的关键代码: btn01.setOnClickListener(new OnClickListener() { @Override public vo ...
- Android UI系列--对话框(一)(AlertDialog,TimePickerDialog,DatePickerDialog,ProgressDialog)
一.Dialog介绍 dialog就是一个在屏幕上弹出一个可以让用户做出一个选择,或者输入额外的信息的对话框,一个对话框并不会沾满我们整个的屏幕,并且通常用于模型事件当中需要用户做出一个决定后才会继续 ...
- Android开发之对话框高级应用
Android开发之对话框高级应用 创建并显示一个对话框非常easy.可是假设想进行一些更高级点的操作,就须要一些技巧了.以下将和大家分享一下对话框使用的一些高级技巧. 1.改变对话框的显示位置: 大 ...
- android从Dialog对话框中取得文本文字
android中Dialog对话框获取文本文字,只需要使用editor的getText方法就可以获得,示例如下:final EditText et = new EditText(this); et.s ...
随机推荐
- javascript 中寻找性能瓶颈
1.如果一个段代码很耗时的话你可以注释掉一部分你认为是很耗时的,或者干脆全部注释掉,然后再一点一点的解开. 2.js优化中最主要的还是对dom操作的优化,单纯的js执行时间是很短的,而js和dom之间 ...
- maven第三章 maven使用入门
3.1编写pom groupId 一个项目名称 artifactId 子项目(模块)名称 version 开发中的版本,稳定的版本 name 项目名称,方便信息交流 http://news.cnblo ...
- 利用eclipse开发php<转>
1.安装php环境 Eclipse支持PHP自动提示 其实如果你已经安装好了php环境(安装过程见)的话,只需要下面2步就可以了.hoho,很简单的. 1,下载eclipse中php的插件phpecl ...
- Android开发手记(7) 按钮类控件的使用
1.点击Button改变页面背景色 通过Button改变页面背景色,首先新建相应的对象,让后绑定到Layout上的元素. final RelativeLayout layout = (Relative ...
- office2010删除多余空行
选择 ctrl+H,弹出 "查找和替换"对话框,在"查找内容"输入"^p^p",并在"替换为"输入"^p&qu ...
- 设置Cacti图形标题能显示中文
1.查看系统是否带有中文字体包 # ls /usr/share/fonts/chinese 如没有则安装 # yum -y install fonts-chinese 2.设置cacti使用的rr ...
- 告诉你GetDC()没有释放造成的后果
最近做的项目中需要显示视频监控窗口,从采集卡中读到图像的数据,需要实时显示出来,而且速度比较快. 由于比较简单,就直接使用了GDI画图,以前复杂的都用openGL啥的工具了,这次这个简单,就直接用GD ...
- myeclipse插件安装
MyEclipse插件安装 安装1: HELP->MuEclipse Configuration Center.切换到SoftWare选项卡. 点击 add site 打开对话框,在对话框中na ...
- Qt 数据库创建表失败原因之数据库关键字
本人数据库新手,在创建表时出现问题,最后经查证,找出问题所在.下面的程序是部分节选,在创建数据库表的时候,起先使用的L24的CreateDB,经测试,一直输出 Create testResult Fa ...
- ASP.NET常用技术之加密解密
在开发项目中有许多数据需要我们进行加密解密操作,这里介绍几个加密解密的方法. 一:MD5加密 MD5加密是一种单向的加密算法,它只能加密,加密后不能进行逆向解密操作,常用于数字签名和加密用户密码. 下 ...