Timer in Android

public class Timer extends Activity {
private TextView tv;
private int cc=0;
private java.util.Timer timr;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timer);
tv=(TextView) findViewById(R.id.textView1);
timr=new java.util.Timer();
timr.scheduleAtFixedRate(new TimerTask() {

@Override
public void run() {
// TODO Auto-generated method stub
TimerMethod();
}
}, 0, 1000);
}

public void TimerMethod() {
this.runOnUiThread(new Runnable() {

public void run() {
// TODO Auto-generated method stub
tv.setText("vaue.."+cc);
cc++;
if(cc>=10)
timr.cancel();
}
});

}

}

Post a Comment

0 Comments