[英]timertask doesn't work!
i have tried using a timertask to refresh a line(after every 1 second) drawn with fixed point coordinates. 我已经尝试使用timertask刷新以固定点坐标绘制的线(每1秒之后)。 But the line doesn't appear to refresh...is there anything wrong in my code?
但是该行似乎没有刷新...我的代码有什么问题吗?
LineRefresh.java: LineRefresh.java:
package LineRefresh.xyz.com;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
public class LineRefresh extends Activity {
DrawView drawView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
}
}
DrawView.java: DrawView.java:
package LineRefresh.xyz.com;
import java.util.Timer;
import java.util.TimerTask;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
}
@Override
public void onDraw(final Canvas canvas) {
paint.setColor(Color.BLACK);
canvas.drawLine(50, 200, 270, 200, paint);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
paint.setColor(Color.BLACK);
canvas.drawLine(50, 200, 270, 200, paint);
}
};
timer.schedule(task, 1000,1000);
}
}
sholud i,instead, place the timertask somewhere else in my code? 我应该在我的代码中将timertask放在其他位置吗?
而是在一定时间后使用Android处理程序更新UI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.