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 ...
随机推荐
- 再谈Cookies欺骗
在上一篇关于cookies欺骗的随笔中,提到的解决方案是把密码MD5加密之后存入cookies中,确实这种方法实现了效果,不过把密码留在客户端等待着去被破解不是一个合适的方法,在此也感谢 @老牛吃肉 ...
- (转)xml节点和元素的关系 .
XML节点是什么呢?当我们在处理XML文件的时候必须要明白XML节点的概念,那么从这里的讲述,你将会了解XML节点对于XML文件的意义,希望对你有所帮助. 在我们学习LINQ删除XML节点之前我们先来 ...
- discuz 和 wordpress 整合注意问题
要先在应用列表里添加自己本身的应用即要保证同步操作,本身也是一个应用,并保证通信成功: 应用和ucenter不在一个机器上,IP都要设定: discuz/uc_client/ 下要有一个接收数据的da ...
- How to install MP4box on CentOS 6
How to install MP4box on CentOS 6 MP4Box is a MP4 multiplexer. It can import MPEG-4 video, DivX, Xvi ...
- 【结构型】Bridge模式
桥接模式是为了将对象的抽象与实现分离,使得它们可以独立变化.简简单单的一句话,却已经是站在了更高抽象层面上来看待.设计.解决问题.平常我们多是对具体问题进行分析.抽象,然后就开始设计,这对多数情况下基 ...
- python查看模块及相关函数帮助
Question: 如何查看正则表达式模块re及其相关函数的意义 1.终端命令行下 python >> import re >> help(re) Help on module ...
- Python自动化运维之10、模块之json、pickle、XML、PyYAML、configparser、shutil
序列化 Python中用于序列化的两个模块 json 用于[字符串]和 [python基本数据类型] 间进行转换 pickle 用于[python特有的类型] 和 [python基本数据类 ...
- C程序设计语言练习题1-21
练习1-21 编写程序entab,将空格串替换为最少数量的制表符和空格,但要保持单词之间的间隔不变.假设制表符终止的位置与练习1-20的detab程序的情况相同.当使用一个制表符或者一个空格都可以打到 ...
- 一元多项式Polynomial的C语言实现
/* 编译器:Dev-c++ 5.4.0 文件名:Polynomial.cpp 代码版本号:1.0 时间:2015年10月9日21:53:26 */ /* 总结: 1.结构体指针指向的区域要手动分配内 ...
- ubuntu12.04安装Vmware Tools
在VMware下安装Ubuntu,那么必须安装VMware-tools,才能获得更好的体验,包括屏幕分辨率.声音.和windows共享剪贴板等等. 个人觉得安装vmware-tools很重要的几点: ...