public class ButtonPlayer implements View.OnClickListener {
private final int[] sounds;
private int soundIndex = -1;
public ButtonPlayer(int... sounds) {
this.sounds = sounds;
}
@Override
public void onClick(View view) {
if (sounds.length != 0) {
soundIndex++;
soundIndex = soundIndex % sounds.length;
MediaPlayer mp = MediaPlayer.create(this, sounds[soundIndex]);
mp.start();
}
}
}
- :
Button one = (Button) this.findViewById(R.id.button1);
one.setOnClickListener(new ButtonPlayer(
R.raw.first_composition,
R.raw.second_composition));
, n . , .
, , . .