通过runOnUiThread改变TextView的值 package com.example.androidthreadtest;import android.app.Activity;import android.os.Bundle;import android.widget.Button;import android.widget.TextView;import butterknife.BindView;import butterknife.Bu
package com.example.androidthreadtest; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.widget.TextView; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; /** * 作者: andli * 时间: 2017/11/1 18:17 * 描述: 通过runOnUiThread改变TextView的值 */ public class MainActivity extends Activity { @BindView(R.id.change_text) Button changeText; @BindView(R.id.text) TextView text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); changeText.setText("通过runOnUiThread改变TextView的值"); } @OnClick(R.id.change_text) public void onViewClicked() { new MyThread().start(); } /** * 通过 runOnUiThread 线程,更新TextView */ class MyThread extends Thread { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { // 延迟操作500毫秒 try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } text.setText("runOnUiThread异步操作"); } }); } } }