package pos.app;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.widget.Button;public class Android extends Activity {/** Called when the activity is first created. */@Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.home);               Button helpButton =(Button) findViewById(R.id.login_help);                     helpButton.setOnClickListener(new Button.OnClickListener(){@Overridepublic void onClick(View v) {Intent intent  = new Intent(AndroidApp.this,MyHandlerActivity.class);startActivity(intent);}                });}}


package pos.app;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Button;

public class MyHandlerActivity extends Activity {

Button button;
MyHandler myHandler;

public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

setContentView(R.layout.home);
setTitle("My Handler Activity");
button = (Button)findViewById(R.id.login_help);

myHandler = new MyHandler();

MyThread m = new MyThread();
new Thread(m).start();
}


class MyHandler extends Handler {

public MyHandler(){

}

public MyHandler( Looper L){
super(L);
}

@Override
public void handleMessage(Message msg){
Log.v("MyHandler", "handleMessage....");
super.handleMessage(msg);
Bundle bundle = msg.getData();
String text = bundle.getString("text");
MyHandlerActivity.this.button.setText(text);

}
}

class MyThread implements Runnable {

@Override
public void run() {

try{
Thread.sleep(1000);
}catch(Exception e){

}

Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putString("text", "handler text");
msg.setData(bundle);

MyHandlerActivity.this.myHandler.sendMessage(msg);
}


}

}



更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android下开源项目
  2. Android(安卓)显示原理简介
  3. Android(安卓)Webview 与js交互汇总
  4. Android导出一个JAR库/Android如何将程序
  5. Android计算器简单逻辑实现
  6. Android之MediaStore应用
  7. 【Android】注解框架(二)-- 基础知识(Java注
  8. Android(安卓)开源项目-StandupTimer学习
  9. Android(安卓)Studio无法新建创建android
  10. Android中的基本组件