为什么其他切换按钮在我的 Onclick 方法中不起作用?
package com.uygulamalar.androidce;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;
public class EglenceliSeslerActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
ToggleButton togg1,togg2,togg3,togg4,togg5,togg6,togg7,togg8,togg9;
MediaPlayer sincap,seytanikahkaha,bateri,kalpatisi,trololo,kedicanini,haha,alkis,dedeler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
togg1 = (ToggleButton) findViewById(R.id.togg1);
togg2 = (ToggleButton) findViewById(R.id.togg2);
togg3 = (ToggleButton) findViewById(R.id.togg3);
togg4 = (ToggleButton) findViewById(R.id.togg4);
togg5 = (ToggleButton) findViewById(R.id.togg5);
togg6 = (ToggleButton) findViewById(R.id.togg6);
togg7 = (ToggleButton) findViewById(R.id.togg7);
togg8 = (ToggleButton) findViewById(R.id.togg8);
togg9 = (ToggleButton) findViewById(R.id.togg9);
sincap = MediaPlayer.create(this, R.raw.dramatiksincap);
seytanikahkaha = MediaPlayer.create(this, R.raw.seytanikahkaha);
bateri = MediaPlayer.create(this, R.raw.bateri);
kalpatisi = MediaPlayer.create(this, R.raw.kalpatisi);
trololo = MediaPlayer.create(this, R.raw.trololo);
kedicanini = MediaPlayer.create(this, R.raw.kedicanini);
haha = MediaPlayer.create(this, R.raw.haha);
alkis = MediaPlayer.create(this, R.raw.alkis);
dedeler = MediaPlayer.create(this, R.raw.dedeler);
togg1.setOnClickListener(this);
togg2.setOnClickListener(this);
togg3.setOnClickListener(this);
togg4.setOnClickListener(this);
togg5.setOnClickListener(this);
togg6.setOnClickListener(this);
togg7.setOnClickListener(this);
togg8.setOnClickListener(this);
togg9.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.togg1:
if(togg1.isChecked()) {
sincap.start();
sincap.setLooping(true);
}
else
sincap.pause();
case R.id.togg2:
if(togg2.isChecked()) {
seytanikahkaha.start();
seytanikahkaha.setLooping(true);
}
else
seytanikahkaha.pause();
case R.id.togg3:
if(togg3.isChecked()) {
bateri.start();
bateri.setLooping(true);
}
else
bateri.pause();
case R.id.togg4:
if(togg4.isChecked()) {
kalpatisi.start();
kalpatisi.setLooping(true);
}
else
kalpatisi.pause();
case R.id.togg5:
if(togg5.isChecked()) {
trololo.start();
trololo.setLooping(true);
}
else
trololo.pause();
case R.id.togg6:
if(togg6.isChecked()) {
kedicanini.start();
kedicanini.setLooping(true);
}
else
kedicanini.pause();
}
}
}
为什么当我点击其他切换按钮时,除了第一个按钮之外,其他切换按钮不播放音频?第一个切换按钮可以很好地播放音频 sincap,但其他按钮则不能播放音频。你能告诉我为什么吗?谢谢。
package com.uygulamalar.androidce;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;
public class EglenceliSeslerActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
ToggleButton togg1,togg2,togg3,togg4,togg5,togg6,togg7,togg8,togg9;
MediaPlayer sincap,seytanikahkaha,bateri,kalpatisi,trololo,kedicanini,haha,alkis,dedeler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
togg1 = (ToggleButton) findViewById(R.id.togg1);
togg2 = (ToggleButton) findViewById(R.id.togg2);
togg3 = (ToggleButton) findViewById(R.id.togg3);
togg4 = (ToggleButton) findViewById(R.id.togg4);
togg5 = (ToggleButton) findViewById(R.id.togg5);
togg6 = (ToggleButton) findViewById(R.id.togg6);
togg7 = (ToggleButton) findViewById(R.id.togg7);
togg8 = (ToggleButton) findViewById(R.id.togg8);
togg9 = (ToggleButton) findViewById(R.id.togg9);
sincap = MediaPlayer.create(this, R.raw.dramatiksincap);
seytanikahkaha = MediaPlayer.create(this, R.raw.seytanikahkaha);
bateri = MediaPlayer.create(this, R.raw.bateri);
kalpatisi = MediaPlayer.create(this, R.raw.kalpatisi);
trololo = MediaPlayer.create(this, R.raw.trololo);
kedicanini = MediaPlayer.create(this, R.raw.kedicanini);
haha = MediaPlayer.create(this, R.raw.haha);
alkis = MediaPlayer.create(this, R.raw.alkis);
dedeler = MediaPlayer.create(this, R.raw.dedeler);
togg1.setOnClickListener(this);
togg2.setOnClickListener(this);
togg3.setOnClickListener(this);
togg4.setOnClickListener(this);
togg5.setOnClickListener(this);
togg6.setOnClickListener(this);
togg7.setOnClickListener(this);
togg8.setOnClickListener(this);
togg9.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.togg1:
if(togg1.isChecked()) {
sincap.start();
sincap.setLooping(true);
}
else
sincap.pause();
case R.id.togg2:
if(togg2.isChecked()) {
seytanikahkaha.start();
seytanikahkaha.setLooping(true);
}
else
seytanikahkaha.pause();
case R.id.togg3:
if(togg3.isChecked()) {
bateri.start();
bateri.setLooping(true);
}
else
bateri.pause();
case R.id.togg4:
if(togg4.isChecked()) {
kalpatisi.start();
kalpatisi.setLooping(true);
}
else
kalpatisi.pause();
case R.id.togg5:
if(togg5.isChecked()) {
trololo.start();
trololo.setLooping(true);
}
else
trololo.pause();
case R.id.togg6:
if(togg6.isChecked()) {
kedicanini.start();
kedicanini.setLooping(true);
}
else
kedicanini.pause();
}
}
}
Why the other toggle buttons not playing audios except than first one when i click on them? The first toggle button plays the audio sincap well but the others dom't play the audios. Can you tell me why? Thx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在每个
case
之后,您应该有一个break
语句,这样您就不会陷入下一个 case。 IE:After each
case
you should have abreak
statement so that you don't fall through to the next case. I.e.: