Skip to content

Instantly share code, notes, and snippets.

@nylen
Created December 16, 2010 19:15
Show Gist options
  • Save nylen/743827 to your computer and use it in GitHub Desktop.
Save nylen/743827 to your computer and use it in GitHub Desktop.
package com.android.myCompass;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class myCompass extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
myTimerTask myTask = new myTimerTask(tv);
Timer myTimer = new Timer();
myTimer.schedule(myTask,1000,1000);
}
}
class myTimerTask extends TimerTask{
int I=0;
TextView tv;
public myTimerTask(TextView tv){//,Activity myParent){
this.tv=tv;
this.tv.setText("timer created");
}
@Override
public void run() {
this.tv.post(new Runnable() {
public void run() {
this.tv.setText("timer started "+I);
this.tv.invalidate();
I++;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment