Android 模式对话框提示Dialog
1、先写一个Dialog类
CustomDialog
package com.example.heng.adtest; import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.widget.Toast; public class CustomDialog {
//声明一个Diaglog
private AlertDialog.Builder builder;
//上下文对象
private Context context; public CustomDialog(Context cnt)
{
this.context = cnt;
} //声明弹出框方法
//buttontext :按钮名称
//title :标题
//message:信息
//callbock:返回信息
public void CreateDialog(String buttontext, String title, String message, final CallBack callbock){
builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
//添加确定按钮
builder.setPositiveButton(buttontext, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//业务逻辑判断
callbock.isConfirm(true);
}
});
builder.create().show();
} public interface CallBack{
public void isConfirm(boolean flag);
}
//声明toasts方法 比较简单的提示框。
public void createToasts(String message) {
Toast.makeText(context,message,Toast.LENGTH_LONG).show();
}
}
2、在MainActivity中调用
package com.example.heng.adtest; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button buttonA;
private Button buttonB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); buttonA = (Button) this.findViewById(R.id.button1);
buttonB = (Button) this.findViewById(R.id.button2);
buttonA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CustomDialog dialog = new CustomDialog(MainActivity.this);
dialog.CreateDialog("确定", "提示", "确定要删除吗?", new CustomDialog.CallBack() {
@Override
public void isConfirm(boolean flag) {
System.out.println("---------->>"+flag);
if (flag){ }
}
});
}
}); buttonB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CustomDialog dialog = new CustomDialog(MainActivity.this);
dialog.createToasts("网路有异常!");
}
);
}
}
3、页面内容
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.heng.adtest.MainActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dialog提示"
android:id="@+id/button1"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="38dp"
android:layout_marginStart="38dp"
android:layout_marginTop="46dp" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:layout_toRightOf="@+id/button1"
android:layout_alignLeft="@+id/button1"
android:layout_alignStart="@+id/button1"
android:layout_marginTop="159dp"
android:text="普通提示" />
</RelativeLayout>
Android 模式对话框提示Dialog的更多相关文章
- Android FlycoDialog 简单实用的自定义Android弹窗对话框之Dialog篇
效果图镇楼 FlycoDialog是一款非常棒的弹窗对话框处理框架,今天在这里主要讲一下他的自定义弹出对话框的功能,这里以第二幅效果图为例,图片已经放在博客最下方,X号自己随便找一个东西代替吧. ...
- Android中制作自定义dialog对话框的实例
http://www.jb51.net/article/83319.htm 这篇文章主要介绍了Android中制作自定义dialog对话框的实例分享,安卓自带的Dialog显然不够用,因而我们要继 ...
- wxPython Modal Dialog 模式对话框
<wxPython in Action>chap 9 笔记 1. Modal Dialog(模式对话框) A modal dialog blocks other widgets from ...
- Android应用Activity、Dialog、PopWindow、Toast窗体加入机制及源代码分析
[工匠若水 http://blog.csdn.net/yanbober 转载烦请注明出处.尊重劳动成果] 1 背景 之所以写这一篇博客的原因是由于之前有写过一篇<Android应用setCont ...
- 【转】【Android】对话框 AlertDialog -- 不错不错
原文网址:http://blog.csdn.net/feng88724/article/details/6171450 本讲介绍一下Android基本组件:对话框AlertDialog. API: j ...
- MFC模式对话框与非模式对话框 消息处理顺序
对话框有两种创建方式:DoModal和Creat. 其中DoModal创建的是模态的对话框,而Creat创建的是非模态的对话框下面总结下他们的不同. 对于模态的对话框,在该对话框被关闭前,用户将不能在 ...
- Bootstrap技术: 模式对话框的使用
一.概述 说到模式对话框,大家肯定都会想到windows下GUI程序,在gui程序中,有大量的对话框. 在web程序中,随着页面交互式功能的增多,有很多场景下也会用到对话框.在html原生的支持下,有 ...
- Android系统对话框
Android系统对话框 效果图 2个按钮的对话框 3个按钮的对话框 自定义View的对话框 单选对话框 多选对话框 列表框 Code XML <?xml version="1.0&q ...
- 【转】 Android常用实例—Alert Dialog的使用
Android常用实例—Alert Dialog的使用 AlertDialog的使用很普遍,在应用中当你想要用户做出“是”或“否”或者其它各式各样的选择时,为了保持在同样的Activity和不改变用户 ...
随机推荐
- project euler 16:Power digit sum
>>> sum([int(i) for i in str(2**1000)]) 1366 >>>
- 闲聊之Python的数据类型 - 零基础入门学习Python005
闲聊之Python的数据类型 让编程改变世界 Change the world by program Python的数据类型 闲聊之Python的数据类型所谓闲聊,goosip,就是屁大点事可以咱聊上 ...
- 小插曲之变量和字符串 - 零基础入门学习Python003
小插曲之变量和字符串 让编程改变世界 Change the world by program 变量 (此处只是省略N多细节,详细通过视频学习) 变量名就像我们现实社会的名字,把一个值赋值给一个名字时, ...
- 做一个正气的杭电人--hdu2500
做一个正气的杭电人 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- ES6新特性-------数组、Math和扩展操作符(续)
三.Array Array对象增加了一些新的静态方法,Array原型上也增加了一些新方法. 1.Array.from 从类数组和可遍历对象中创建Array的实例 类数组对象包括:函数中的argumen ...
- Silverlight 结合ArcGis 在地图上画线
原文 http://www.dotblogs.com.tw/justforgood/archive/2012/05/10/72085.aspx 先来看看完成后的画面,我从桃园画到高雄,再由高雄画到香港 ...
- EasyUI的下拉选择框控件方法被屏蔽处理方式
1.html标签如下 <div id="selectMap" style="top: 1px;left: 80px;position: absolute;" ...
- 格而知之7:我所理解的Runtime(2)
消息发送(Messaging) 8.以上便是runtime相关的一些数据结构,接下来我们回看一开始的疑问: objc_msgSend()函数在执行的过程中是如何找到对应的类,找到对应的方法实现的呢? ...
- 解决 jsp:include 引用文件时出现乱码的问题
阐述问题前,先来看一下下面这张图片左侧iframe中的乱码页面: 这个就是让我纠结好一阵子的乱码截图: 这个乱码页面中是使用了<jsp:include>引用标签后出现了这个问题: 源码截图 ...
- python 笔记1--基础类型
list 操作 append() 添加最外面 insert(pos,content) 插入指定地方 pop() 删除最外面 pop(pos) 删除指定地方 list中可以有list,且能用二维数组的方 ...