赞
踩
如果时间大于一小时,则显示时 分 秒 ,否则只显示 分 秒,如果不足一分钟,则只显示秒
Activity中的相关声明:
- private static final long DOWN_TIMER_COUNT = 3671000;
- private MyDownTimer mDownTimer;
-
onCreate()中
- mTimerTv = (TextView)this.findViewById(R.id.timer_notice_tv);
- mDownTimer = new MyDownTimer(DOWN_TIMER_COUNT, 1000);
- mDownTimer.start();
- class MyDownTimer extends CountDownTimer
- {
-
- public MyDownTimer(long millisInFuture, long countDownInterval)
- {
- super(millisInFuture, countDownInterval);
- }
-
- @Override
- public void onTick(long mill)
- {
- long a = mill/1000/3600;
- long b = mill/1000%3600/60;
- long c = mill/1000%3600%60;
- if(mill/1000 >= 3600)
- {
- mTimerTv.setText(String.format(getString(R.string.sdk_timer_tv_a), a, b, c));
- }
- else if(mill/1000 >= 60)
- {
- mTimerTv.setText(String.format(getString(R.string.sdk_timer_tv_b), b, c));
- }
- else if(mill/1000 > 0)
- {
- mTimerTv.setText(String.format(getString(R.string.sdk_timer_tv_c), c));
- }
- }
-
- @Override
- public void onFinish()
- {
- mTimerTv.setVisibility(View.GONE);
- showToast("begin to exam");
- }
- }
strings.xml
- <string name="sdk_timer_tv_a" formatted="false">距离考试\n%s时%s分%s秒</string>
- <string name="sdk_timer_tv_b" formatted="false">距离考试\n%s分%s秒</string>
- <string name="sdk_timer_tv_c" formatted="false">距离考试\n%s秒</string>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。