抽奖按钮第一时间想到的就是handler通过postDelayed方法来改变textview的值,鉴于时间比较着急,就采用这个方案。
private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 0: try { thread_1.interrupt(); handler.removeCallbacks(thread_1); thread_1 = null; }catch (Exception e){ toast(e.getMessage()); } break; case 1: SetTextNum_1();//修改textview的值 break; } }
thread_1 = new Thread(new Runnable() { @Override public void run() { Message message = new Message(); message.what = 1; handler.sendMessage(message); handler.postDelayed(thread_1,100); } }); thread_1.start();
postDelayed方法中,第一个参数写thread_1,也就是线程名,千万不要写this!!!!!