gistfile1.txt package com.example.androidthreadtest;import android.app.Activity;import android.os.Bundle;import android.os.Handler;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.os.Handler; 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("通过Handler Post改变TextView的值"); } @OnClick(R.id.change_text) public void onViewClicked() { Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { // 延迟500毫秒执行 try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } text.setText("Handler Post"); } }); } }