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传递参数的更多相关文章

  1. Android Handler传递参数动态更新UI界面demo

    package com.example.demo_test; import android.app.Activity; import android.os.Bundle; import android ...

  2. Android自定义对话框

    在android中有自带的对话框,为了美观,很多开发者会使用自定义对话框,如下图: 点击“弹出自定义对话框按钮后”显示如图效果. 首先要自己定义一个xml文件定义自己对话框的样式: <?xml ...

  3. Android: 启动另外的APP及传递参数(转)

    转载自:http://blog.csdn.net/iefreer/article/details/8812585 有时候需要从一个APP中启动另外一个APP,比如Twitter/微信等. 如果你不知道 ...

  4. Android 自定义对话框

    Android实现自定义对话框效果: 核心代码: package com.example.diydialog; import android.os.Bundle; import android.app ...

  5. Android,使用Intent或Bundle传递参数,跳转页面。

    (1)使用Intent跳转页面: 第一个activity:MainActivity.java中: Intent myIntent = new Intent(); myIntent.putExtra(& ...

  6. Android——软键盘操作+fragment之间传递参数+TextView限制字数,显示"..."

    原文地址: Android 手动显示和隐藏软键盘 Android隐藏输入法键盘(hideSoftInputFromInputMethod没有效果) Android Fragment传递参数_Fragm ...

  7. Android自定义组件系列【13】——Android自定义对话框如此简单

    在我们的日常项目中很多地方会用到对话框,但是Android系统为我们提供的对话框样子和我们精心设计的界面很不协调,在这种情况下我们想很自由的定义对话框,或者有的时候我们的对话框是一个图片,没有标题和按 ...

  8. Android自定义对话框(Dialog)位置,大小

    代码: package angel.devil; import android.app.Activity;import android.app.Dialog;import android.os.Bun ...

  9. Android 自定义对话框(Dialog)位置,大小

    代码: package angel.devil; import android.app.Activity; import android.app.Dialog; import android.os.B ...

随机推荐

  1. [转]WINDOW进程通信的几种方式

    windows进程通信的几种方式 1 文件映射 文件映射(Memory-Mapped Files)能使进程把文件内容当作进程地址区间一块内存那样来对待.因此,进程不必使用文件I/O操作,只需简单的指针 ...

  2. ThreadPool 线程池的作用

    相关概念: 线程池可以看做容纳线程的容器: 一个应用程序最多只能有一个线程池: ThreadPool静态类通过QueueUserWorkItem()方法将工作函数排入线程池: 每排入一个工作函数,就相 ...

  3. Linux C 程序 文件操作(Linux系统编程)(14)

    文件操作(Linux系统编程) 创建一个目录时,系统会自动创建两个目录.和.. C语言实现权限控制函数 #include<stdio.h> #include<stdlib.h> ...

  4. EasyUI –tree、combotree学习总结

    EasyUI –tree.combotree学习总结 一.   tree总结 (一).tree基本使用 tree控件是web页面中将数据分层一树形结构显示的. 使用$.fn.tree.defaults ...

  5. 小米2s换了屏幕后不能近距离对焦,拆过后无法对焦?

    主要问题就是小米2/2S手机中壳套后摄像头的位置,里面还有一个正方形的黑色塑胶垫片,一般拆机后这个垫片是不会掉出来的,所以一般上盖时也是直接把中壳合上后上螺丝. 这样安装基本会导致塑胶垫片把摄像头顶住 ...

  6. 指针之 *((volatile unsigned long *)(x))解析

    今天重新温习了一下C语言的指针部分,突然想到了经常会碰见的一种宏定义:#define PGAS (*((volatile unsinged long *)(x))) 在解析该宏定义前,先看看指针变量的 ...

  7. PHP将二进制文件存入数据库以及从数据库中读取二进制文件

    <?php $file = 'abcd.sqlite'; mysql_connect('localhost','root','123456'); mysql_select_db('zblog') ...

  8. JSONP 含jquery 实例

     前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Soc ...

  9. ubuntu下安装ffmpeg和X264

    第一步:安装必要的库 $:-dev libtheora-dev libx11-dev zlib1g-dev 第二步:安装SDL(否则可能编译不出ffplay) $:-dev $:-dev libsdl ...

  10. C# 白话系列之——白话委托

    今天看到首页有个委托的文章,但大都写的太专业,而且没有实用的例子场景.正好昨天做了一个有关委托的功能,所以也来凑个热闹,用白话掰掰 一.委托是什么 我们都知道数据类型,简单点的如,想给一个变量赋值整数 ...