Dialog 自定义使用3(回调点击事件)
1 , Dialog布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dialog_bg"
android:orientation="vertical" > <TextView
android:id="@+id/title" //标题
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="14dp"
android:textColor="@color/login_hint"
android:textSize="@dimen/text_size_18" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp" > <TextView
android:id="@+id/confirm" //确认
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/btn_confirm_selector"
android:gravity="center"
android:textColor="@color/white"
android:textSize="@dimen/text_size_16" /> <TextView
android:id="@+id/cancel" //取消
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@drawable/btn_cancel_selector"
android:gravity="center"
android:textColor="@color/login_hint"
android:textSize="@dimen/text_size_16" />
</LinearLayout> </LinearLayout>
2, 自己定义dialog 类
public class ConfirmDialog extends Dialog {
private Context context;
private String title;
private String confirmButtonText;
private String cacelButtonText;
private ClickListenerInterface clickListenerInterface;
public interface ClickListenerInterface {
public void doConfirm();
public void doCancel();
}
public ConfirmDialog(Context context, String title, String confirmButtonText, String cacelButtonText) {
super(context, R.style.MyDialog); // 定义的是样式 , 占时省略
this.context = context;
this.title = title;
this.confirmButtonText = confirmButtonText;
this.cacelButtonText = cacelButtonText;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
init();
}
public void init() {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.confirm_dialog, null);
setContentView(view);
TextView tvTitle = (TextView) view.findViewById(R.id.title);
TextView tvConfirm = (TextView) view.findViewById(R.id.confirm);
TextView tvCancel = (TextView) view.findViewById(R.id.cancel);
tvTitle.setText(title);
tvConfirm.setText(confirmButtonText);
tvCancel.setText(cacelButtonText);
tvConfirm.setOnClickListener(new clickListener());
tvCancel.setOnClickListener(new clickListener());
Window dialogWindow = getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
dialogWindow.setAttributes(lp);
}
public void setClicklistener(ClickListenerInterface clickListenerInterface) {
this.clickListenerInterface = clickListenerInterface;
}
private class clickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int id = v.getId();
switch (id) {
case R.id.confirm:
clickListenerInterface.doConfirm();
break;
case R.id.cancel:
clickListenerInterface.doCancel();
break;
}
}
};
}
3 ,使用
public static void Exit(final Context context) {
final ConfirmDialog confirmDialog = new ConfirmDialog(context, "确定要退出吗?", "退出", "取消");
confirmDialog.show();
confirmDialog.setClicklistener(new ConfirmDialog.ClickListenerInterface() {
@Override
public void doConfirm() {
// TODO Auto-generated method stub
confirmDialog.dismiss(); // 关闭
//toUserHome(context);
AppManager.getAppManager().AppExit(context); //退出
}
@Override
public void doCancel() {
// TODO Auto-generated method stub
confirmDialog.dismiss();
}
});
}
Dialog 自定义使用3(回调点击事件)的更多相关文章
- echart自定义浮窗 增加点击事件
一:情景 做一个柱状图,需要在柱状图显示lable,并且浮窗上每个条目可以被点击或者跳转. 我使用的做图插件是echarts,但是echart的浮窗是图片,而且不可以被点击,不能识别html,而且这个 ...
- android 自定义listview无法响应点击事件OnItemClickListener
如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话,那么默认focus是交给了子控件,而ListView的Item能被选中的基础是它能获取Focus,也就是说我 ...
- flutter 处理dialog点击事件回调
flutter 处理dialog点击事件回调 import 'package:flutter/material.dart'; import 'package:scoped_model/scoped_m ...
- 隐藏自定义的tabbar之后,push到B视图,B视图的键盘工具条无法响应点击事件
我的情况如下: 在TabbarViewController中隐藏了系统的tabbar,然后自定义tabbar,A B C D 4个视图都有UINavigationController,A视图 使用的是 ...
- ListView使用自定义适配器的情况下实现适配器的文本和图标控件点击事件执行Activity界面中的方法
ListView使用的是自定义适配器,列表项的布局文件中含有文本和图标,实现文本区域和图标区域的点击事件. 实现思路:在自定义适配器MyArrayAdapter 类型中自定义接口和接口方法,分别设置文 ...
- ListView使用自定义适配器的情况下实现适配器的控件点击事件执行Activity界面中的方法
如果ListView使用的是自定义的适配器,比如MyArrayAdapter extends ArrayAdapter<String> 那么,如何实现适配器中的点击事件执行activity ...
- 关于百度地图InfoWindow响应自定义布局点击事件
大概讲解: 在百度地图上显示一个marker,当marker被点击后,显示自定义的View.当自定义的View被点击后,响应不同Button的点击事件.被百度这个infowindo里面的view坑惨了 ...
- RecyclerView的点击事件添加-------接口回调的形式添加
package com.example.recyclerviewdemo; import android.support.v7.widget.RecyclerView; import android. ...
- Android ---------高德卫星地图绘制多个点和点的点击事件自定义弹窗
最近开发中,遇到一个多个点绘制,并实现点击事件,出现自定义窗口显示相关信息等功能,所以写了这篇博客. 从后台请求数据,得到多个经纬度,然后绘制在地图上,并实现点击,出现相关信息(自定义弹框实现) 先来 ...
随机推荐
- jQuery源码分析_工具方法(学习笔记)
expando:生成唯一JQ字符串(内部使用) noConflict():防止冲突 isReady:DOM是否加载完成(内部) readyWait:等待多少文件的计数器(内部) holdReady() ...
- Android app与PC端交互
app提交信息到PC端mysql数据库 新建名为SignActivity package com.example.administrator.success; import android.app.A ...
- Android:日常学习笔记(10)———使用LitePal操作数据库
Android:日常学习笔记(10)———使用LitePal操作数据库 引入LitePal 什么是LitePal LitePal是一款开源的Android数据库框架,采用了对象关系映射(ORM)的模式 ...
- [MEF] 学习之一 入门级的简单Demo
MEF 的精髓在于插件式开发,方便扩展. 我学东西,习惯性的先搞的最简单的Demo出来,看看有没有好玩的东东,然后继续深入.这个博文,不谈大道理,看demo说事儿. 至于概念,请google ,大把大 ...
- 0522 HTML表单 CSS基础
一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,“无序列表”的意思. li:lis ...
- 算法(Algorithms)第4版 练习 1.5.3
id数组和treesize数组变化情况: 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 10 components 9 0 1 2 3 4 5 6 7 8 9 1 1 ...
- stdcall、cdecl详解(以及WINAPI和CALLBACK之类的宏对应什么)
转自:http://blog.csdn.net/huanjieshuijing/article/details/5822942 对_stdcall 的理解在C语言中,假设我们有这样的一个函数:int ...
- HTML5 学习记录——0
2015/08/19 HTML5的标签功能划分:基础.格式.表单.框架.图像.音视频.链接.列表.表格.样式.元信息.编程 1.HTML基础标题 <h1> - <h6>段落 & ...
- JS获取ListBox所有项
JS代码: var listbox = document.getElementById("<%=lbCustom.ClientID %>"); var values = ...
- 分享知识-快乐自己:解决 Maven 无法下载 fastdfs-client-java 依赖。
因为fastdfs-client-java-1.27-SNAPSHOT.jar这个依赖包在maven中央仓库是没有的. 需要自己编译源码成jar本地安装到maven 的本地仓库,安装完以后就能正常引用 ...