ImageButton を作成し、クリックするとサウンドを再生する次のコードがあります。
ImageButton SoundButton1 = (ImageButton)findViewById(R.id.sound1);
SoundButton1.setImageResource(R.drawable.my_button);
SoundButton1.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN ) {
mSoundManager.playSound(1);
return true;
}
return false;
}
});
問題は、押したときに ImageButton の画像を変更することです。OnTouchListener はタッチをオーバーライドしているようで、画像の変更を許可していません。OnTouchListener を削除するとすぐに、ImageButton を押すと別の画像に切り替わります。OnTouchListener を使用しながら、ImageButton で画像を変更する方法についてのアイデアはありますか? どうもありがとうございました!