Android 计时器

在我的应用我有15启动计数器,我有一个按钮,有一个动画和声音,问题是,我想关闭声音和按钮的动画和背景更改为再踢上的声音单击当计数器达到0 这是我试图锁定代码和声音,但它不工作了,我错了,你有什么想法? 代码:
MediaPlayer mediaPlayer;
 int contatore;
 TextView Display;
 Button b1;

 private StartAppAd startAppAd = new StartAppAd(this);

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.b1);
  contatore = 15;
  b1 = (Button)findViewById(R.id.b1);
  Display = (TextView)findViewById(R.id.contatore);
  final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.pistola);

  b1.setOnClickListener(new Button.OnClickListener() { 
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
      contatore --;
      Display.setText(""+contatore);
     for (int contatore = 0; contatore!= 0; ){
       contatore = (Integer) null;
       mediaPlayer = null;
       }
    arg0.startAnimation(animRotate);
    final Button button1 = (Button)findViewById(R.id.b1);
    button1.setBackgroundResource(R.drawable.deserteagle_1);
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
      public void run() { 
       button1.setBackgroundResource(R.drawable.deserteagle_0); 
      } 
    }, 100); 

    mediaPlayer = MediaPlayer.create(getBaseContext(),R.raw.b1);
    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
      @Override
      public void onPrepared(MediaPlayer mediaPlayer) {
       // TODO Auto-generated method stub
       mediaPlayer.start();
       mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
        public void onCompletion(MediaPlayer mediaPlayer) {
         mediaPlayer.release();
        };
       });
        }
       });
   }
  });
提前致谢
本文地址 :CodeGo.net/7832433/ 
------------------------------------------------------------------------------------------------------------------------- 
1. 好吧......从看你的代码,尝试这些变化。 这一点:
final Button button1 = (Button)findViewById(R.id.b1);
button1.setBackgroundResource(R.drawable.deserteagle_1);
这样:
runOnUiThread(new Runnable() {
 // you already have `b1` that points to `R.id.b1`, so use that
 // instead of using `findViewById` again
 b1.setBackgroundResource(...);
});
我不知道这是什么部分是应该做的:
   for (int contatore = 0; contatore!= 0; ){
     contatore = (Integer) null;
     mediaPlayer = null;
     }
此外,一定要在包装 Display.setText runOnUiThread  
2.  我解决了这种方式,计数器的问题,现在不仅仍然扮演另一声音而不是这个和停止动画和改变按钮的背景
private int contatore = 15;
   private Object mediaPlayer;
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
      contatore --;
      Display.setText(""+contatore);
      if(this.contatore <= 0)
    {
      this.contatore=1;
       this.mediaPlayer = null;
       }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值