I'm new to Android and I would like to play a sound depending on the button that was pressed by the user.
I managed to play a sound on button press but I had to specify the file that I wanted to be played.
What I want to do is to find a way to dynamically set the R.raw.arthaswhat5 parameter so that it is set up to the last button pressed.
public void listen(View w){
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.arthaswhat5);
mediaPlayer.start();
}
I thought that naming the buttons the same way as my files could help but I don't really understand how this R thing works... I know I can get the v.getId() int to know which button is pressed but I can't use this id to play a sound accordingly...