读书人

既然:Android禁止其他子线程来更新由

发布时间: 2012-04-01 17:23:46 作者: rapoo

既然:Android禁止其他子线程来更新由UI thread创建的试图
那为什么,这段代码可以更新TextView里的内容?

Java code
package com.wo;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class Ss3Activity extends Activity {    Thread otherthread = null;    private TextView tv;    private Button button;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        tv = (TextView) this.findViewById(R.id.tv);        otherthread = new Thread("other thread") {            @Override            public void run() {                tv.setText("come baby");            }        };        otherthread.start();    }}


[解决办法]
有这样一种说法,在onResume之前,界面还没绘制好,可以在子线程里进行设置(如果你的线程在onResume之前执行完),但是这样没有意义吧

读书人网 >Android

热点推荐