views:

116

answers:

2

Hello togehter

I need a regular method in my app. The problem is: the following timer in the code do its action just one time. And the timer do it only(the one time) if i do an action( touch the display) after the time(2000) is over. U know what i mean? Maybe it have sth to do with the "OnTouchListener"?

public class DrawView extends View implements OnTouchListener{
Timer timer = new Timer();

public DrawView(Context context)
{
timer.schedule(new Task(this), 2000);
}
public boolean onTouch(View view, MotionEvent event)
{}
}

class Task extends TimerTask  
{

  private DrawView _dw;
  public Task(DrawView dw){
  this._dw = dw;}

  public void run()  
  {
        _dw.newgame();
  }

} 
A: 

The timer is doing what he should do. You should use the schedule Method of the Timer but instead scheduleAtFixedRate().

Roflcoptr
Thank you but i used the 3-arguments method
Simon Schubert
A: 

shcedule(task, 0, 2000) - use the 3-argument method. The second argument is the delay, and the third is the period. See Timer#schedule(..)

Bozho