在我的应用我有15启动计数器,我有一个按钮,有一个动画和声音,问题是,我想关闭声音和按钮的动画和背景更改为再踢上的声音单击当计数器达到0 这是我试图锁定代码和声音,但它不工作了,我错了,你有什么想法? 代码:
本文地址 :CodeGo.net/7832433/
-------------------------------------------------------------------------------------------------------------------------
1. 好吧......从看你的代码,尝试这些变化。 这一点:
2. 我解决了这种方式,计数器的问题,现在不仅仍然扮演另一声音而不是这个和停止动画和改变按钮的背景
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;
}