需要在Android倒数计时器 [英] Countdown Timer required on Android

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

问题描述

下面就是我对格式的倒计时讨论的链接(MM:SS)在Java中:

Here is the link where i have discussed about a countdown timer of format(mm:ss) in Java:

<一个href="http://stackoverflow.com/questions/3491027/java-console-$c$c-for-stopwatch-timer">http://stackoverflow.com/questions/3491027/java-console-$c$c-for-stopwatch-timer

现在我要显示(和更新),它在Android的一个TextView。任何线索?

Now i want to display (and update) it in a textview in android. Any clue?

推荐答案

倒计时

您将使用一个文本字段,并使用更新其内容的<一个href="http://developer.android.com/intl/fr/reference/android/os/CountDownTimer.html">CountDownTimer,或检查拉胡尔的回答在这个同样的问题。

You'll use a TextField and update its content using CountDownTimer, or check Rahul's answer in this same question.

要计数

在你的Activity

In your Activity

import android.widget.Chronometer;

...

private Chronometer crono;

protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 setContentView(R.layout.screen_crono);    

 this.crono = (Chronometer) findViewById(R.id.calling_crono);

    startCrono();
}

public void startCrono() {
 crono.setBase(SystemClock.elapsedRealtime());
 crono.start();
}

要阻止它

crono.stop();

在XML布局screen_crono

In the XML Layout screen_crono

<Chronometer
    android:id="@+id/calling_crono"
 android:layout_height="wrap_content" 
 android:layout_width="wrap_content" 
    android:textStyle="bold"
 android:textSize="14sp"/>

要设置一个TextView里面,我不认为这是可能的。将它放置在它的右边或在其左边,这取决于你想要什么。

To set it inside a TextView, I don't think that's possible. Place it to its right or to its left, depending on what you want.

如果这不是你想要的,我希望它可以帮助别人。

If this is not what you wanted, I hope it helps someone else.

这篇关于需要在Android倒数计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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