package com.example.myandroid01;

 import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
/**
* Android 封装Dialog
* @Describe:
* @package: com.example.myandroid01
* @author shaobn
* @date 2015-9-14 下午2:35:49
*/
public class MainActivity extends ActionBarActivity {
private Button button1;
private Button button2;
private CustomDialog cdCustomDialog;
private static final String TITLE = "Warning";
private static final String MESSAGE = "确定删除?";
private static final String BUTTONNAME = "确定";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) this.findViewById(R.id.button1);
button2 = (Button) this.findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
cdCustomDialog = new CustomDialog(MainActivity.this);
cdCustomDialog.createDialog(TITLE,MESSAGE, BUTTONNAME,new DialogInter() { @Override
public void callback(boolean flag) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "已点击", 1).show();
}
});
}
});
button2.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
cdCustomDialog = new CustomDialog(MainActivity.this);
cdCustomDialog.toastDialog("sure");
}
});
}
}
 package com.example.myandroid01;

 import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.widget.Toast;
/**
* 自定义dialog类
* @Describe:
* @package: com.example.myandroid01
* @author shaobn
* @date 2015-9-14 下午2:36:17
*/
class CustomDialog {
private Context context;
private AlertDialog.Builder builder;
public CustomDialog(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
public void createDialog(String title,String message,String buttonName,final DialogInter dialogInter){
builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton(buttonName, new OnClickListener() { @Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
dialogInter.callback(true);
}
});
builder.create().show();
}
public void toastDialog(String message){
Toast.makeText(context, message,Toast.LENGTH_LONG).show();
} }
interface DialogInter{
void callback(boolean flag);
}

Android 封装Dialog的更多相关文章

  1. Android封装TitleBar基本适用所有常规开发

    Android封装TitleBar基本适用所有常规开发 github地址:https://github.com/SiberiaDante/SiberiaDanteLib/blob/master/sib ...

  2. Android PopupWindow Dialog 关于 is your activity running 崩溃详解

    Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...

  3. Android 自定义Dialog类,并在Activity中实现按钮监听。

      实际开发中,经常会用到Dialog,比如退出时候会弹出是否退出,或者还有一些编辑框也会用Dialog实现,效果图如下: 开发中遇到的问题无非在于如果在Activity中监听这个Dialog中实现的 ...

  4. Android 对话框(Dialog)大全 建立你自己的对话框

    Android 对话框(Dialog)大全 建立你自己的对话框 原文地址: http://www.cnblogs.com/salam/archive/2010/11/15/1877512.html A ...

  5. Android自定义Dialog

    Android开发过程中,常常会遇到一些需求场景——在界面上弹出一个弹框,对用户进行提醒并让用户进行某些选择性的操作, 如退出登录时的弹窗,让用户选择“退出”还是“取消”等操作. Android系统提 ...

  6. Android中Dialog

    在Android中,Dialog是一个非常重要的UI, 它可以方便的给用户提示,用最简洁的方式向用户展示信息, 以下的图片是Dialog的一个整体架构,通过它,可以总体对Dialog有一个很清晰的认识 ...

  7. android之dialog

    先编写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...

  8. Android之Dialog详解

    Android中的对话框形式大致可分为五种:分别是一般对话框形式,列表对话框形式,单选按钮对话框,多选按钮对话框,自定义对话框. 在实际开发中,用系统的对话框会很少,因为太丑了,美工不愿意,多是使用自 ...

  9. Android中Dialog对话框

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

随机推荐

  1. JS懒加载

    4.如何使用js懒加载图片       a.懒加载图片是基于jquery.js的,所以: <script src="jquery.js" type="text/ja ...

  2. angularJS自定义指令模板替换

    <html> <head> <meta charset="utf-8"/> <title></title> </h ...

  3. C++ Primer Pluse_6_课后题

    #include <iostream> #include <cctype> #include <array> #include <string> #in ...

  4. Codeforces Round #376 (Div. 2) C. Socks---并查集+贪心

    题目链接:http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,每只都有一个颜色,现在他的妈妈要去出差m天,然后让他每天穿第 L 和第 R 只 ...

  5. c#导出excel(转)

    C#导出Excel文件实例代码 2010-08-03 14:10:36|  分类: 软件编程 |  标签:excel  c#导出excel   |字号大中小 订阅 /// <summary> ...

  6. Swift-07-析构器deinit

    析构器只适用于类类型,当一个类的实例被释放之前,析构器会被立即调用.析构器用关键字deinit来标识,类似于构造器用init来标识. 原理: Swift会自动释放不再需要的实例以释放资源.Swift通 ...

  7. An unknown Subversion error occurred. (code = 155037)

    这是因为在svn更新时意外中断引起的. 我的解决办法:如果本地没有更改,只是单纯获取svn的项目,则另起一个文件夹,重新checkout: 如果是本地有更改,则复制到新的文件夹,重新update.

  8. ibatis传入数组或List

    小结一下ibatis框架下,传入参数为数组类型或者是List类型的sql写法.标签里面都不需要表名 1.传入字符串数组,不需要标明parameterClasss,数组和List类型对象一样都可以用&l ...

  9. iOS 证书及配置文件介绍

    1.Certification(证书) 证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种: 1)Developer Certification(开发证书) 安装在电脑上提供权限:开发人员通过 ...

  10. php自定义错误处理和try{}catch(){}学习

    <?php //语法错误 //运行时的错误 //逻辑错误 //php的错误报告级别 // display_errors; // ini_set("display_errors" ...