AndroidはCountDownTimerクラスでカウントダウン機能を実現
1082 ワード
public class MainActivity extends Activity {
private MyCount mc;
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)findViewById(R.id.show);
mc = new MyCount(70000, 1000);
mc.start();
}
class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
System.out.println(" ");
}
@Override
public void onTick(long millisUntilFinished) {
Date date = new Date(millisUntilFinished);
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
String str = sdf.format(date);
System.out.println(str);
tv.setText(" 70 ("+millisUntilFinished / 1000 +")...");
}
@Override
public void onFinish() {
tv.setText("finish");
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mc.cancel();
}
}