2013-05-21 46 views
0

它在第一个水龙头, 工作良好,但随后在第二次点击它没有回应。它等待1秒,然后执行'generateRandom()'方法框架动画doesnt运行第二次点击

任何人都可以帮忙吗?

我的代码:

paper.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      player.setImageResource(R.drawable.papel1); 
      setTimerImage4Bot(); 
     } 
    }); 


    public void setTimerImage4Bot() { 
     try { 
      handler = new Handler(); 
      frameAnimation = (AnimationDrawable)bot.getDrawable(); 
      frameAnimation.setCallback(bot); 
      frameAnimation.setVisible(true, true); 

      frameAnimation.start(); 
      Log.i("BaoAnh", "START"); 

      handler.postDelayed(new Runnable(){ 
       public void run(){ 
        frameAnimation.stop(); 
        Log.i("BaoAnh","STOP"); 
        generateRandom(); 
       } 
      },1000); 

     }catch (Exception e) { 

     } 
} 
+0

I se ldom使用Handler,你有没有试过timer.schedule? –

+0

实现一个新的TimerTask像新的TimerTask(){@覆盖公共无效运行(){//做你的东西在这里}} –

+0

@JeffLee你有任何例子吗? :(...我很想尝试,但我不知道如何......“<...我没有做任何事情与线程,处理程序,定时器之前:(( – zBaoAnhLe

回答

0

创建一个自定义类AnimationTask和实现接口的TimerTask

private class AnimationTask implements TimerTask{ 
    @Override 
    public void run(){ 
    // Run you code here 
    } 
} 

里面你的onClick方法:

Timer timer = new Timer(); 
timer.schedule(new AnimationTask(), 1000); 

希望我可以帮助你: D