Created
December 16, 2010 19:15
-
-
Save nylen/743827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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