首页 > 学院 > 开发设计 > 正文

handle.post 跳到主线程中执行

2019-11-09 16:53:32
字体:
来源:转载
供稿:网友
package com.example.che;import android.os.Bundle;import android.os.Handler;import android.app.Activity;import android.widget.TextView;public class MainActivity extends Activity { public Handler h = new Handler(); TextView tv01; @Override PRotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv01=(TextView) this.findViewById(R.id.wenzi); yunXing(); } public void yunXing(){ new Thread(){ public void run() { h.post(new Runnable() { //跳到主线程中更新UI @Override public void run() { // TODO Auto-generated method stub tv01.setText("xu hai tao"); } }); } }.start(); } }

备注:


post中的代码实际上是在主线程中执行的


FR:海涛高软(QQ技术交流群:386476712)


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表