Reputation: 63
I'm new to android development and i was wondering if there is a way to retrieve the matching sound files depending on an image click. I have 6 images that are in random order so i want to play the appropriate sound depending on what image i clicked. Thanks!
Upvotes: 0
Views: 683
Reputation: 28599
As Mentioned by @LeartS, you could set the tag
property of the image:
img1.setTag("\path\to\audio.mp3");
or
android:tag="@string/some_file"
And retrieve it when needed
public void onClick(View v){
play(img1.getTag().toString());
}
Another another way that you could do it would by using the IDs of the image views
Create a final ID
final int ID_IMG_APPLE = 0x0001;
Set the ID to the view
img1.setId(ID_IMG_APPLE);
Check the ID when a view is clicked:
public void onClick(View v){
switch(v.getId()){
case ID_IMG_APPLE:
play("apple.mp3");
break;
}
}
Upvotes: 0