gistfile1.txt package com.example.androidthreadtest;import android.app.Activity;import android.os.AsyncTask;import android.os.Bundle;import android.widget.Button;import android.widget.TextView;import butterknife.BindView;import butterknife.
package com.example.androidthreadtest; import android.app.Activity; import android.os.AsyncTask; 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("通过AsyncTask改变TextView的值"); } @OnClick(R.id.change_text) public void onViewClicked() { new MyAsyncTask().execute(); // 执行异步更新UI操作 } class MyAsyncTask extends AsyncTask{ @Override protected String doInBackground(String... params) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String s) { text.setText("AsyncTask更新"); } } }