Basic Android Tutorial: Countdown Timer Code

Jun 28, 2010

Countdown Timer:BasicAndroid Tutorial

Here is some basic code to make a timer that counts down.
You can specify the start value you want and the amount you want it to count down by.

package com.android.countdown;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

public class CountDownTest extends Activity {

TextView tv; //textview to display the countdown

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

tv = new TextView(this);
this.setContentView(tv);

//5000 is the starting number (in milliseconds)
//1000 is the number to count down each time (in milliseconds)
MyCount counter = new MyCount(5000,1000);

counter.start();

}

//countdowntimer is an abstract class, so extend it and fill in methods
public class MyCount extends CountDownTimer{

public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}

@Override
public void onFinish() {
tv.setText(”done!”);
}

@Override
public void onTick(long millisUntilFinished) {
tv.setText(”Left: ” + millisUntilFinished/1000);

}
This android-tutorial is Taken from http://dewful.com/?p=3

To take an Online Android Tutorial Course Click Here

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Share with others

No Responses so far | Have Your Say!

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

rss
Карта