I have a problem with create a new class to count time. This is my code:
Button btcheck = (Button)findViewById(R.id.btcheck);
btcheck.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
Time aa = new Time();
aa.RunTime();
}
});
And
public class Time extends MainActivity {
public void RunTime() {
startTime = SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
}
public Runnable updateTimerThread = new Runnable() {
public void run() {
updatedTime = SystemClock.uptimeMillis() - startTime;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
stime="" + mins + ":" + String.format("%02d", secs) + ":" + String.format("%03d", milliseconds);
txttime.setText(stime + " ");
customHandler.postDelayed(this, 0);
};
}
However it does'nt work as I expect. Hope you help me.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…