Android 封装Dialog
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的更多相关文章
- Android封装TitleBar基本适用所有常规开发
Android封装TitleBar基本适用所有常规开发 github地址:https://github.com/SiberiaDante/SiberiaDanteLib/blob/master/sib ...
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...
- Android 自定义Dialog类,并在Activity中实现按钮监听。
实际开发中,经常会用到Dialog,比如退出时候会弹出是否退出,或者还有一些编辑框也会用Dialog实现,效果图如下: 开发中遇到的问题无非在于如果在Activity中监听这个Dialog中实现的 ...
- Android 对话框(Dialog)大全 建立你自己的对话框
Android 对话框(Dialog)大全 建立你自己的对话框 原文地址: http://www.cnblogs.com/salam/archive/2010/11/15/1877512.html A ...
- Android自定义Dialog
Android开发过程中,常常会遇到一些需求场景——在界面上弹出一个弹框,对用户进行提醒并让用户进行某些选择性的操作, 如退出登录时的弹窗,让用户选择“退出”还是“取消”等操作. Android系统提 ...
- Android中Dialog
在Android中,Dialog是一个非常重要的UI, 它可以方便的给用户提示,用最简洁的方式向用户展示信息, 以下的图片是Dialog的一个整体架构,通过它,可以总体对Dialog有一个很清晰的认识 ...
- android之dialog
先编写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...
- Android之Dialog详解
Android中的对话框形式大致可分为五种:分别是一般对话框形式,列表对话框形式,单选按钮对话框,多选按钮对话框,自定义对话框. 在实际开发中,用系统的对话框会很少,因为太丑了,美工不愿意,多是使用自 ...
- Android中Dialog对话框
布局文件xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
随机推荐
- Qt high DPI
http://doc.qt.io/qt-5/highdpi.html Qt Support Ability to provide pixmaps or artwork for high resolut ...
- Magento - Rewrite机制一窥
看一个url例子 http://localhost/magento/index.php/customer/account/login 这里假定http://localhost/magento/ 是ma ...
- GIS 学习及参考站点
地理信息论坛 GIS空间站 GISALL 广东水利厅 flex版的
- LightOj1190 - Sleepwalking(判断点与多边形的位置关系--射线法模板)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1190 题意:给你一个多边形含有n个点:然后又m个查询,每次判断点(x, y)是否在多边 ...
- WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.
我当初安装sql server的时候选的Window Authentication mode,没选SQL Server Windows Authentication. 后来做WPF时连接数据库时需要一 ...
- ionic 报错%1 is not a valid Win32 application
Fixed the problem by installing python version 3.0 and above will do下载Python3.0或以上版本 python官网传送门:htt ...
- 通过 ec2-api / boto 调用 OpenStack 功能
通过 ec2-api / boto 调用 OpenStack 功能 OpenStack 支持 amazon ec2 的 api,并能通过 python 库 boto 来进行调用.目前,社区在把 ec2 ...
- zookeeper安装和应用场合(名字,配置,锁,队列,集群管理)
安装和配置详解 本文介绍的 Zookeeper 是以 3.2.2 这个稳定版本为基础,最新的版本可以通过官网http://hadoop.apache.org/zookeeper/ 来获取,Zookee ...
- java yum安装的环境变量设置
如何(怎样)在CentOS 6.X 或 redhat 上使用安装JDK runtime environment (openjdk) ? CentOS 6.X 和 5.X 自带有OpenJDK runt ...
- RFS_窗口或区域之间的切换
1. 测试用例描述 [前置条件]: 1. 已经登录系统 [测试步骤]: 1. 验证登录成功 2. 选择[用户管理]菜单 3. 打开[新增用户]页面 4. 输入必填字段,点击[Submit]按钮 [预 ...