You don't have a loop in run() function, try to change it like this:
@Override
public void run() {
TextView tv1 = (TextView) findViewById(R.id.tv);
while(true){
showTime(tv1);
try {
Thread.sleep(1000);
}catch (Exception e) {
tv1.setText(e.toString());
}
}
}
Be careful, it will run forever though. You should also use a handler to perform changes on UI from another thread, it can be done by example below:
Handler mHandler = new Handler();
@Override
public void run() {
final TextView tv1 = (TextView) findViewById(R.id.tv);
while(true){
try {
mHandler.post(new Runnable(){
@Override
public void run() {
showTime(tv1);
}
);
Thread.sleep(1000);
}catch (Exception e) {
//tv1.setText(e.toString());
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…