android AlertDialog常见使用
android AlertDialog常见使用
简单提示框:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("HELLO");
alertDialog.setMessage("HELLO,WORLD");
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "OK" + arg1,
Toast.LENGTH_SHORT).show();
arg0.dismiss();
}
});
alertDialog.show();
确认,取消框:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("HELLO");
alertDialog.setMessage("Are you sure to delete?");
alertDialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub Toast.makeText(getApplicationContext(),
"OK" + arg1, Toast.LENGTH_SHORT).show();
arg0.dismiss();
}
});
alertDialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub Toast.makeText(getApplicationContext(),
"Canceled" + arg1, Toast.LENGTH_SHORT)
.show();
arg0.dismiss();
}
}).create();
alertDialog.show();
单选列表弹出框:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("HELLO");
String[] items = new String[] { "123", "345" };
alertDialog.setSingleChoiceItems(items, 0,
new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "" + arg1,
Toast.LENGTH_LONG).show();
}
});
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "OK" + arg1,
Toast.LENGTH_SHORT).show();
arg0.dismiss();
}
});
alertDialog.show();
多列表选择弹出框:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("HELLO");
String[] items = new String[] { "123", "345" };
alertDialog.setMultiChoiceItems(items,
new boolean[]{true,false},
new DialogInterface.OnMultiChoiceClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1,
boolean arg2) {
// TODO Auto-generated method stub }
});
alertDialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub Toast.makeText(getApplicationContext(),
"OK" + arg1, Toast.LENGTH_SHORT).show();
arg0.dismiss();
}
});
alertDialog.show();
android AlertDialog常见使用的更多相关文章
- Android Studio常见对话框(普通对话框、单选对话框、多选对话框、进度条对话框、消息对话框、自定义对话框)
Android Studio常见对话框(普通对话框.单选对话框.多选对话框.进度条对话框.消息对话框.自定义对话框) 1.普通对话框 2.单选对话框 3.多选对话框 4.进度条对话框 5.消息对话框 ...
- Android下常见动画
摘要:Android中常见的的动画有三种:属性动画.补间动画.帧动画. 注.因为前两种内容较多,后补 一.属性动画 二.补间动画 三.帧动画:本质是将一些连贯的图片加载形成连贯的动画效果 1.在Dra ...
- 二十一、Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读
术语和概念 屏幕尺寸 屏幕的物理尺寸,以屏幕的对角线长度作为依据(比如 2.8寸, 3.5寸). 简而言之, Android把所有的屏幕尺寸简化为三大类:大,正常,和小. 程序可以针对这三种尺寸的屏幕 ...
- Android中常见的MVC模式
MVC模式的简要介绍 MVC是三个单词的缩写,分别为: 模型(Model),视图(View)和控制Controller). MVC模式的目的就是实现Web系统的职能分工. Model层实现系统中的业务 ...
- Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读
术语和概念 屏幕尺寸 屏幕的物理尺寸,以屏幕的对角线长度作为依据(比如 2.8寸, 3.5寸). 简而言之, Android把所有的屏幕尺寸简化为三大类:大,正常,和小. 程序可以针对这三种尺 ...
- Android Bitmap 常见的几个操作:缩放,裁剪,旋转,偏移
Android Bitmap 相关操作 常见的几个操作:缩放,裁剪,旋转,偏移 很多操作需要 Matrix 来支持:Matrix 通过矩阵来处理位图,计算出各个像素点的位置,从而把bitma ...
- Android中常见的内存泄漏
为什么会产生内存泄漏? 当一个对象已经不需要再使用了,本该被回收时,而有另外一个正在使用的对象持有它的引用从而导致它不能被回收,这导致本该被回收的对象不能被回收而停留在堆内存中,这就产生了内存泄漏. ...
- (转载)android开发常见编程错误总结
首页 › 安卓开发 › android开发 android开发常见编程错误总结 泡在网上的日子 / 文 发表于2013-09-07 13:07 第771次阅读 android,异常 0 编辑推荐:稀 ...
- android中常见对话框之一AlertDialog
在Android应用中,有多种对话框:Dialog.AlertDialog.ProgressDialog.时间.日期等对话框. (1)Dialog类,是一切对话框的基类,需要注意的是,Dialog类虽 ...
随机推荐
- [转]C#综合揭秘——细说多线程(上)
引言 本文主要从线程的基础用法,CLR线程池当中工作者线程与I/O线程的开发,并行操作PLINQ等多个方面介绍多线程的开发. 其中委托的BeginInvoke方法以及回调函数最为常用. 而 I/O线程 ...
- PKU_campus_2018_D Chocolate
思路: 题目链接http://poj.openjudge.cn/practice/C18D/ kruskal过程中使用乘法原理计数. 实现: #include <bits/stdc++.h> ...
- The lion king 经典句型摘录
What am I going to do with him? Everything the light touches is our kingdom. But I thought a king ca ...
- bat判断服务是否启动
sc query|find "tomcat6" && echo yes || echo nosc query|find "eventlog" & ...
- 剑指offer8 旋转数组的最小数字
一种错误写法: class Solution { public: int minNumberInRotateArray(vector<int> rotateArray) { int len ...
- freemarker特殊字符输出
期望输出: #{fefefefwewrerwerwrrrre}${fffqqqwwwwwwwwwwwwwwww} 但是以上解析ftl时候会报错!!!!!!!!!!!! 解决办法: 方法1:使用${r& ...
- Docker安装Oracle12C,导入dmp文件出现ORA-12170错误
oracle版本为 sath89/oracle-12c oracle基本信息 hostname: localhost port: 1521 sid: xe username: system passw ...
- set容器几个关键函数
set在OI中非常好用,归纳几种常见的功能qwq #include<iostream> #include<cstdio> #include<set> //set容器 ...
- mysql5.7 在Centeros 6 下自动安装的shell脚本
概述: 此脚本实现了在Centeros 6版本下自动安装mysql5.7到目录 /opt/mysql-5.7*并且做软连接映射到 /usr/local/mysql,自动修改root密码为:123456 ...
- mysql在线开启或禁用GTID模式
在线开启步骤: 1.要求: (1)必须是5.7.6版本以上的mysql (2)GTID状态为OFF 2.开启步骤: (1):SET GLOBAL ENFORCE_GTID_CONSISTENCY = ...