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 ...
随机推荐
- C++ sizeof操作符的用法和strlen函数的区别
摘要:本人首先介绍了C++中sizeof操作符的用法和注意事项,其次对比了和strlen的区别和使用,方便大家在写代码的时候查阅,和面试.笔试的时候复习. 目录: sizeof的用法: sizeof和 ...
- AspectJ的简单使用
aspectj是一款优秀的面向切面的编程框架,下面就简单介绍一下入门教程吧: 1.官网下载AspectJ的jar包,我这里下的是最新版本1.8.7的. 2.因为AspectJ.jar 是一个可执行的j ...
- Maven Dependency Scope用法
原帖地址:http://uule.iteye.com/blog/2087485 官方API描述 Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个 ...
- JQ跑马灯
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- StringBuilder的Append()方法会比+=效率高
StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id from " + databa ...
- C# Json数据反序列化为Dictionary并根据关键字获取指定值
Json数据: { "dataSet": { "header": { "returnCode": "0", " ...
- Cassandra1.2文档学习(12)—— hint机制
参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/dml/dml_about_ ...
- 详解AngularJS中的filter过滤器用法
系统的学习了一下angularjs,发现angularjs的有些思想根php的模块smarty很像,例如数据绑定,filter.如果对smarty比较熟悉的话,学习angularjs会比较容易一点.这 ...
- 国产CPU研究单位及现状
1.国产CPU主要研制单位 (1)高性能通用CPU(“大CPU”,主要应用于高性能计算及服务器等) 主要研发单位:中国科学院计算所.北大众志.国防科技大学.上海高性能集成电路设计中心 (2)安全适用计 ...
- db2使用Java存储过程实现MD5函数
1.数据库版本 2.Java脚本 import java.security.MessageDigest; import COM.ibm.db2.app.UDF; public class MD5UDF ...