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 ...
随机推荐
- UVa11384
题意:给定正整数n,求把1,2,--,n中所有书都变成0的最少操作次数,每次操作可从序列中选择一个或多个整数,同时减去一个相同的正整数. 分析:如1,2,3,4,5,6, 第一步将4,5,6同时减4, ...
- Item47
STL迭代器分类:input迭代器.output迭代器.forward迭代器.bidirectional迭代器.random access迭代器. Input迭代器:只能向前移动,一次一步,客户只读取 ...
- 【Linux】rsync同步文件 & 程序自启动
rsync使用 1. 为什么使用rsync? rsync解决linux系统下文件同步时, 增量同步问题. 使用场景: 线上需要定时备份数据文件(视频资源), 使用rsync完成每天的增量备份. 参见: ...
- Mac OS 踩坑指南
前言 其实mac os本身还是很不错的,软硬结合使得其性能.效率.续航得到了很好的优化. 但是毕竟是一个"小众"操作系统,很多在Win上已经用习惯的东西在这里都没有,或者完全不一样 ...
- jquery 点击查看,收起特效
<div class="all"> <p><a href="javascript:;" id="onvk"&g ...
- php计算代码运行时间与内存使用的一段代码
计算运行时间及内存使用,代码如下: <?php //开始计时 $HeaderTime = microtime(true);//参数true表示返回浮点数值 //代码 //... printf(& ...
- 我用的一些Node.js开发工具、开发包、框架等总结
开发工具 1.WebStorm,毫无疑问非他莫属,跨平台,强大的代码提示,支持Nodejs调试,此外还支持vi编辑模式,这点我很喜欢. 2.做些小型项目用Sublime Text. 3.Browser ...
- FIFO、LRU、OPT这三种置换算法的缺页次数
考虑下述页面走向: 1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2,1,2,3,6 当内存块数量分别为3时,试问FIFO.LRU.OPT这三种置换算法的缺页次数各是多少? 答:缺页定义 ...
- hdu 4622 Reincarnation SAM模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有Q次区间查询(Q <= 10000),问区 ...
- 【 Quartz】使用 JobListener (任务监听器可实现) 我想在一个任务执行后在执行第二个任务怎么办呢
http://liuzidong.iteye.com/blog/1147528 Quartz之JobExecutionException 博客分类: Java Quartz quartzjobexec ...