当前位置: 代码迷 >> Android >> 既然:Android禁止其他子线程来更新由UI thread创建的试图解决思路
  详细解决方案

既然:Android禁止其他子线程来更新由UI thread创建的试图解决思路

热度:41   发布时间:2016-05-01 21:58:27.0
既然: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之前执行完),但是这样没有意义吧
  相关解决方案