直接上代码
public class MainActivity extends AppCompatActivity { TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView=findViewById(R.id.tv); new Thread(){ @Override public void run() { super.run(); final Handler handler=new Handler(Looper.myLooper()){ @Override public void handleMessage(Message msg) { textView.setText(msg.obj+""); } }; int i=0; while (true){ Message message = handler.obtainMessage(); message.obj=++i; message.sendToTarget(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }.start(); } }