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. SVN提交注意点

    一.提交之前先更新 1.         SVN更新的原则是要随时更新,随时提交.当完成了一个小功能,能够通过编译并且自己测试之后,谨慎地提交. 2.         如果在修改的期间别人也更改了sv ...

  2. v2.0

    #include <stdio.h>#include <string.h>#include <ctype.h>typedef struct node{ char l ...

  3. AMQP协议

    当前各种应用大量使用异步消息模型,并随之产生众多消息中间件产品及协议,标准的不一致使应用与中间件之间的耦合限制产品的选择,并增加维护成本. AMQP是一个提供统一消息服务的应用层标准协议,基于此协议的 ...

  4. ubuntu下交叉编译windows c程序

    简介 采用mingw32可以在linux下直接编译c程序输出为windows下的exe程序或dll链接库. 个人编译的纯c程序(不含winapi),主要是c99程序,通常采用gcc/cc编译调试后,再 ...

  5. 【Android测试】【随笔】Bugtags初体验

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5410003.html 前言 早晨接到一个临时任务,就是尝试 ...

  6. Popwindow自定义动画(nexus5不支持暂未解决)

    遇到一个问题,先记录一下 PopWindow自定义动画 import android.app.Activity; import android.graphics.drawable.BitmapDraw ...

  7. 1069 Nim游戏

    1069 Nim游戏 基准时间限制:1 秒 空间限制:131072 KB 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜.假设A ...

  8. Stakeholder Risk Management

    In this article we'll address the people swirling around your project: stakeholders. You'll find som ...

  9. 使用sql语句查询日期在一定时间内的数据

    使用sql语句查询日期在一周内的数据 select * from ShopOrder where datediff(week,ordTime,getdate()-1)=0   //查询当天日期在一周年 ...

  10. 【转】使用git、git-flow与gitlab工作

    转自:http://www.tuicool.com/articles/BZJRj2 使用git.git-flow与gitlab工作 时间 2013-11-02 00:40:39  Axb的自我修养 原 ...