package com.hanqi.testapp22; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.os.Handler; public class TestActivity6 extends AppCompatActivity { TextView tv_5; TextView tv_6; Button bt_3,bt_4,bt_5; int i = 10; Handler hl=new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 1: if (i==20) { bt_3.setEnabled(false); bt_4.setEnabled(true); bt_5.setEnabled(false); return; } i++; tv_6.setText(i + ""); hl.sendEmptyMessageDelayed(1, 2000); hl.removeMessages(2); bt_3.setEnabled(false); break; case 2: if (i==1) { bt_4.setEnabled(false); bt_5.setEnabled(false); bt_3.setEnabled(true); return; } i--; tv_6.setText(i+""); hl.sendEmptyMessageDelayed(2,2000); hl.removeMessages(1); bt_4.setEnabled(false); break; case 3: if (i==10) { bt_5.setEnabled(false); } hl.removeMessages(1); hl.removeMessages(2); bt_5.setEnabled(false); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test6); tv_5=(TextView)findViewById(R.id.tv_5); tv_6=(TextView)findViewById(R.id.tv_6); bt_3=(Button)findViewById(R.id.bt_3); bt_4=(Button)findViewById(R.id.bt_4); bt_5=(Button)findViewById(R.id.bt_5); }