我有一個從15開始的計數器,並且我有一個具有動畫和聲音的按鈕,問題是我想要關閉聲音和按鈕的動畫並更改當計數器達到0時,點擊播放另一個聲音背景在我的應用程序中禁用計數器android
這是我試圖鎖定儀表和聲音但它不起作用的代碼,我錯誤地使用它有任何想法?
代碼:
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();
};
});
}
});
}
});
在此先感謝
再解釋什麼是「行不通」。你的意思是計數器永遠不會改變,或者聲源永不改變? –
計數器不會停止,並且應用程序正常工作 –