handle.post 跳到主线程中执行

来源:互联网 发布:juniper networks mac 编辑:程序博客网 时间:2024/06/09 16:22
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)

1 0
原创粉丝点击