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. 尚硅谷大数据视频_Shell视频教程免费下载
  2. 《尚硅谷韩顺平Go语言核心编程》全套视频
  3. 看图说话,脏读、不可重复读、幻读分别是什
  4. [DM]聚类
  5. 浮动(License)许可使用紧张优化方案
  6. 请将你的 if else 设计成责任链模式!
  7. 通过代码原理教你搞懂SGD随机梯度下降、B
  8. 盒模型和定位
  9. 0323作业
  10. markdown语法和Emmet插件的使用