Android 自定义对话框使用静态Handler传递参数
JsdMainDialog.java
package com.jsd.demo; import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView; /**
*
* @author jiangshide
*
*/
public class JsdMainDialog extends Activity { private Context mContext; private Button mSub;
private TextView mResultValue; public static Handler handler = new Handler(); @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getViewById();
} public void getViewById(){
mContext = this;
mSub = (Button) this.findViewById(R.id.sub);
mResultValue = (TextView) this.findViewById(R.id.resultValue);
mResultValue.setText("没有通过Handler处理");
mSub.setOnClickListener(listener);
} private OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sub:
final String flag = "rqbackvalue";
DialogCustomer dc = new DialogCustomer(mContext,flag);
dc.show();
handler = new Handler(){
public void handleMessage(Message msg) {
String resultFlag = msg.getData().getString("flags");
if(resultFlag.equalsIgnoreCase(flag)){
mResultValue.setText("这是通过Handler处理过后来显示数据的");
mResultValue.setTextColor(Color.CYAN);
mResultValue.setTextSize();
}
};
};
break; default:
break;
}
}
};
}
DialogCustomer.java:
package com.jsd.demo; import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button; /**
*
* @author jiangshide
*
*/
public class DialogCustomer extends Dialog { private Context mContext; private Button ok;
String flag; public DialogCustomer(Context c,String flag) {
super(c);
this.mContext = c;
this.flag = flag;
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
getViewById();
} public void getViewById(){
ok = (Button) this.findViewById(R.id.dialog_ok);
ok.setOnClickListener(listener);
} private android.view.View.OnClickListener listener = new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.dialog_ok:
Message msg = new Message();//获取设置一个信息保存点
msg.what=;
msg.getData().putString("flags", flag);
JsdMainDialog.handler.sendMessage(msg);//把数据放进LOOPER队列里
dismiss();
break;
}
}
};
}
dialog.xml:
<?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="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="当返回时把参数传递过去并执行判断后的操作"
/>
<Button
android:id="@+id/dialog_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请点击"
/>
</LinearLayout>
Android 自定义对话框使用静态Handler传递参数的更多相关文章
- Android Handler传递参数动态更新UI界面demo
package com.example.demo_test; import android.app.Activity; import android.os.Bundle; import android ...
- Android自定义对话框
在android中有自带的对话框,为了美观,很多开发者会使用自定义对话框,如下图: 点击“弹出自定义对话框按钮后”显示如图效果. 首先要自己定义一个xml文件定义自己对话框的样式: <?xml ...
- Android: 启动另外的APP及传递参数(转)
转载自:http://blog.csdn.net/iefreer/article/details/8812585 有时候需要从一个APP中启动另外一个APP,比如Twitter/微信等. 如果你不知道 ...
- Android 自定义对话框
Android实现自定义对话框效果: 核心代码: package com.example.diydialog; import android.os.Bundle; import android.app ...
- Android,使用Intent或Bundle传递参数,跳转页面。
(1)使用Intent跳转页面: 第一个activity:MainActivity.java中: Intent myIntent = new Intent(); myIntent.putExtra(& ...
- Android——软键盘操作+fragment之间传递参数+TextView限制字数,显示"..."
原文地址: Android 手动显示和隐藏软键盘 Android隐藏输入法键盘(hideSoftInputFromInputMethod没有效果) Android Fragment传递参数_Fragm ...
- Android自定义组件系列【13】——Android自定义对话框如此简单
在我们的日常项目中很多地方会用到对话框,但是Android系统为我们提供的对话框样子和我们精心设计的界面很不协调,在这种情况下我们想很自由的定义对话框,或者有的时候我们的对话框是一个图片,没有标题和按 ...
- Android自定义对话框(Dialog)位置,大小
代码: package angel.devil; import android.app.Activity;import android.app.Dialog;import android.os.Bun ...
- Android 自定义对话框(Dialog)位置,大小
代码: package angel.devil; import android.app.Activity; import android.app.Dialog; import android.os.B ...
随机推荐
- [转帖]译文:如何使用SocketAsyncEventArgs类(How to use the SocketAsyncEventArgs class)
原文链接:http://norke.blog.163.com/blog/static/276572082011828104315941/ 引言 我一直在探寻一个高性能的Socket客户端代码.以前,我 ...
- PLSQL往Oracle数据库插入中文后变为问号 和 启动PLSQL时提示NLS_LANG在客户端不能确定的解决办法
PLSQL往Oracle数据库插入中文后变为问号 和 启动PLSQL时提示NLS_LANG在客户端不能确定的解决办法 1.检查服务器的字符编码 Select * from V$NLS_PARAMETE ...
- 认识HTML5
引言,认识两个标准制定的组织 在讲什么是Html5之前得先了解两个组织:WHATWG :网页超文本技术工作小组(英语:Web Hypertext Application Technology Work ...
- php字符串首字母转换大小写的实例分享
php中对字符串首字母进行大小写转换的例子. in: 后端程序首字母变大写:ucwords() <?php $foo = 'hello world!'; $foo = ucwords($foo) ...
- ThinkPHP图片上传
ThinkPHP是国内比较流行的轻量级的PHP框架,它在国内流行的一个最主要的因素在于它的说明文档非常健全完善,以及它源码内的注释都是中文的,方便于英语能力较差的程序员学习. 图片上传在网站里是很常用 ...
- 《Java并发编程实战》读书笔记(更新中)
一.简介 1.多线程编程要注意的几点: 安全性:永远不发生糟糕的事情 活跃性:某件正确的事情最终会发生(不会发生无限循环或者死锁) 性能:正确的事尽快发生(上下文切换消耗之类的) 二.线程安全 1.为 ...
- 【python】开始python之旅
上午开始抽空学习python,具体内容如下: (1)安装了python 2.7 (2)安装了notepad ++,安装它之前,在notepad++和Sublime Text之间纠结了一下,baidu了 ...
- python中文件的复制
python中文件的复制 python的os模块有很多文件目录相关的函数,但没有提供直接复制文件的函数,当然可以通过边都边写的方式复制文件.想要直接复制文件可以通过shutil模块 shutil模块是 ...
- C语言控制语句总结(if else for switch while break continue)
一.if语句 1表达式 if(条件表达式) 语句 注: (1)条件表达式,一般为逻辑表达式或关系表达式,但也可以是任何数值类型,如整型.实型.字符型.指针型数据等. (2)语句,由于是C语言的语句,而 ...
- make问题:make[1] entering directory
执行make distclean命令.