Playing A Sound File When A List Item Is Clicked
Just a disclaimer, I'm very new to both android and Java. The end product that I'm going after in this is a soundboard like application. I want to display a list of sounds that th
Solution 1:
Change your values array this way:
<string-arrayname="alex_sounds"><item>soundfile</item></string-array>
Then your listener becomes: (packageName is a string representing the package of your R file: e.g. "com.example.main"
)
@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int pos, long id) {
StringselectedFromList= getItemAtPosition(pos);
intresId= getResources().getIdentifier(selectedFromList, "raw", packageName);
MediaPlayermp= MediaPlayer.create(AlexList.this, resId);
mp.start();
}
This will play the file which name you selected in your list view, from your res/raw
folder.
(Coded quickly in StackOverflow, there may be syntax errors)
Post a Comment for "Playing A Sound File When A List Item Is Clicked"