Android的月蚀:如何设置倒计时在android系统定时器 [英] android Eclipse: how to set a count down timer in android

查看:122
本文介绍了Android的月蚀:如何设置倒计时在android系统定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用系统中的电流,以显示倒计时特定的时间在我的Andr​​oid应用程序。提前致谢。我需要设置一个倒数计时器应该知道多少时间是留给确切时间,这是在12点30分这code。

  //启动时间
        字符串string13 =日期+六时三十分00秒;
        日期time13 =新的SimpleDateFormat(MM-DD-YY HH:MM:SS)解析(string13)。
        日历calendar13 = Calendar.getInstance();
        calendar13.setTime(time13);        // 时间结束
        字符串string14 =日期+13:30:00;
        日期time14 =新的SimpleDateFormat(MM-DD-YY HH:MM:SS)解析(string14)。
        日历calendar14 = Calendar.getInstance();
        calendar14.setTime(time14);        // 确切时间
        字符串string15 =日期+12:30:00;
        日期Z =新的SimpleDateFormat(MM-DD-YY HH:MM:SS)解析(string15)。
        日历C15 = Calendar.getInstance();
        c15.setTime(Z);


解决方案

使用低于code你的目标。

  startB =(按钮)this.findViewById(R.id.button1);
startB.setOnClickListener((OnClickListener)本);
文字=(TextView的)findViewById(R.id.textView1);
@覆盖
公共无效的onClick(视图v){
    新CountDownTimer(30000,1000){//调整毫秒数这里        公共无效onTick(长millisUntilFinished){
        text.setText(+的String.format(%d个最小%D秒,
                    TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)
                    TimeUnit.MILLISECONDS.toSec​​onds(millisUntilFinished) -
                          TimeUnit.MINUTES.toSec​​onds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
    }    公共无效onFinish(){
       text.setText(完成了!);
    }
 }。开始();}

或尝试以下链接结果
http://steve.odyfamily.com/?p=12

I want to show countdown to a particular time in my android application by using the systems current. thanks in advance. I need to set a countdown timer that should tell how much time is left to "exact time " which is 12:30 in this code.

// start time
        String string13 = date + " 06:30:00";  
        Date time13 = new SimpleDateFormat("MM-dd-yy HH:mm:ss").parse(string13);
        Calendar calendar13 = Calendar.getInstance();
        calendar13.setTime(time13);

        // end time
        String string14 = date + " 13:30:00";  
        Date time14 = new SimpleDateFormat("MM-dd-yy HH:mm:ss").parse(string14);
        Calendar calendar14 = Calendar.getInstance();
        calendar14.setTime(time14);

        // exact time
        String string15 = date + " 12:30:00";
        Date Z = new SimpleDateFormat("MM-dd-yy HH:mm:ss").parse(string15);
        Calendar c15 = Calendar.getInstance();
        c15.setTime(Z); 

解决方案

Use below code to your goal.

startB = (Button) this.findViewById(R.id.button1);
startB.setOnClickListener((OnClickListener) this);
text = (TextView) findViewById(R.id.textView1);


@Override
public void onClick(View v) {
    new CountDownTimer(30000, 1000) { // adjust the milli seconds here

        public void onTick(long millisUntilFinished) {
        text.setText(""+String.format("%d min, %d sec", 
                    TimeUnit.MILLISECONDS.toMinutes( millisUntilFinished),
                    TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - 
                          TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
    }

    public void onFinish() {
       text.setText("done!");
    }
 }.start();

}

OR try below link
http://steve.odyfamily.com/?p=12

这篇关于Android的月蚀:如何设置倒计时在android系统定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆