Dialog中更新Activity的数据显示
/**
* 自定义Dialog监听器
* @author Kael.Chen
*
*/
public interface PriorityListener {
/**
* 回调函数,用于在Dialog的监听事件触发后刷新Activity的UI显示
*/
public void refreshPriorityUI();
}
2、为自定义Dialog增加带监听器参数的构造函数:
private PriorityListener listener; public PriorityDlg(Context context) {
super(context);
this.context = context;
// TODO Auto-generated constructor stub
} public PriorityDlg(Context context, int theme) {
super(context, theme);
this.context = context;
} public PriorityDlg(Context context, int theme, PriorityListener listener) {
this(context, theme);
this.listener = listener;
}
3、在Dialog中需要的地方去调用回调函数,比如在ListView的选择事件触发时:
dlg_priority_lvw.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
dismiss();
listener.refreshPriorityUI();
}
});
4、然后你在Activity中使用带监听器参数的构造函数去实例化自定义Dialog,并实现监听器中声明的回调函数就可以了:
//为优先级选择按钮增加监听器
task_simple_form_priority.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
//弹出任务优先级选择对话框
PriorityDlg dlg = new PriorityDlg(SimpleTaskActivity.this, R.style.dlg_priority, new PriorityDlg.PriorityListener() { @Override
public void refreshPriorityUI() {
//这里就是用来刷新Activity的UI显示的,如果你需要用到从Dialog传回的数据,你可以把该数据存储在全局变量中或者作为回调函数的参数传递进来
Toast.makeText(SimpleTaskActivity.this, "完成选择", Toast.LENGTH_SHORT).show();
}
});
dlg.show(); }
});
解析(创建自定义对话框):
PriorityDlg dlg = new PriorityDlg(SimpleTaskActivity.this, R.style.dlg_priority);
return dlg;
R.style.dlg_priority设置了对话框使用的样式文件,只是让对话框去掉标题栏,当然你也可以通过代码来完成这种效果:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 对话框样式 -->
<style name="dlg_priority" parent="@android:Theme.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
Dialog中更新Activity的数据显示的更多相关文章
- (转)Android在子线程中更新Activity中UI的方法
转:http://blog.sina.com.cn/s/blog_3fe961ae0100mvc5.html 在Android平台下,进行多线程编程时,经常需要在主线程之外的一个单独的线程中进行某些处 ...
- Andriod中自定义Dialog样式的Activity点击空白处隐藏软件盘(Dialog不消失)
一.需求触发场景: 项目中需要出发带有EditText的Dialog显示,要求在编辑完EditText时,点击Dilog的空白处隐藏软键盘.但是Dialog不会消失.示例如下: 二.实现方法: 发布需 ...
- android 不能在子线程中更新ui的讨论和分析
问题描写叙述 做过android开发基本都遇见过 ViewRootImpl$CalledFromWrongThreadException,上网一查,得到结果基本都是仅仅能在主线程中更改 ui.子线程要 ...
- android 反纠结app开发: 在线程中更新view
大体上想实现一个思路: 对一个view 的内容进行不停地变化, 通过按钮停止这种变化,以达到随机选择的目的. 开发过程中 使用textview 模拟, 建立线程 mythread = new Thr ...
- Android中半透明Activity效果另法
Android中的Activity有没有类似于像Windows程序样的窗口式显示呢? 答案当然是有. 下图就是一个窗口式Activity的效果图: 下面就说说实现过程: 首先看看AndroidMani ...
- Android在子线程中更新UI(二)
MainActivity如下: package cc.testui2; import android.os.Bundle; import android.view.View; import andro ...
- Android在子线程中更新UI(一)
MainActivity如下: package cc.testui1; import android.os.Bundle; import android.os.Handler; import andr ...
- 老问题:Android子线程中更新UI的3种方法
在Android项目中经常有碰到这样的问题,在子线程中完成耗时操作之后要更新UI,下面就自己经历的一些项目总结一下更新的方法: 方法一:用Handler 1.主线程中定义Handler: Handle ...
- 隐藏软键盘(解决自定义Dialog中无法隐藏的问题)
/** * Dialog中隐藏软键盘不管用 * @param activity */ public static void HideSoftKeyBoard(Activity activity){ t ...
随机推荐
- 第一遍练习:手抄一份 CRUD 并上传截图
- CentOS7 yum方式安装 MongoDB 3.4 复制集
CentOS7 yum方式安装 MongoDB 3.4 环境.准备 Centos7 系统 配置MongoDB的yum源,添加文件/etc/yum.repos.d/mongodb-org-3.4.rep ...
- Architecture of a Java Compiler
Architectural Overview A modern optimizing compiler can be logically divided into four parts: Th ...
- Centos调整时间时区
一台VPS的时间出错,使用常规手段修改均失败.提示hwclock failed : ntpdate stdtime.sinica.edu.tw 如果你的 VPS 提示没有 ntpdate 这个命令,可 ...
- 中小团队快速构建SQL自动审核系统
SQL审核与执行,作为DBA日常工作中相当重要的一环,一直以来我们都是通过人工的方式来处理,效率低且质量没办法保证.为了规范操作,提高效率,我们决定引入目前市面上非常流行的SQL自动审核工具Incep ...
- js便签笔记(2)——DOM元素的特性(Attribute)和属性(Property)
1.介绍: 上篇js便签笔记http://www.cnblogs.com/wangfupeng1988/p/3626300.html最后提到了dom元素的Attribute和Property,本文简单 ...
- js便签笔记(1)——说说HTMLCollection、NodeList以及NamedNodeMap
介绍 在js的dom操作中,除了常用的document.html**Element之外,还有三个集合对象,即HTMLCollection.NodeList以及NamedNodeMap.试看以下操作: ...
- centos 关闭selinux 临时关闭selinux 报错 setenforce: setenforce() failed
关闭selinux的方法有两种:临时关闭和永久关闭. 查看selinux的状态:estatus [root@--- ~]# sestatus SELinux status: enabled SELin ...
- 前端富文本编辑器 vue-html5-editor
1..项目创建与初始化 在安装好脚手架的依赖后,要执行 npm install vue-html5-editor -S 来安装这个富文本插件,由于这个富文本插件的图标是依赖font-awesome.c ...
- CentOS7.2配置Hadoop2.6.5
Hadoop配置文件 /etc/profile 配置Java和Hadoop环境 export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk export CLAS ...