I have a project with around 100-200 clickable views all of which have OnClickListener
. I want to make them play a sound when onClick()
method gets fired. I know how to play a sound with MediaPlayer
, however, I don't want to write the MediaPlayer.start()
in every single onClick()
method.
Is it possible to have a single interface that extends from OnClickListener
which will enable all the buttons to produce a sound when clicked?
After writing the question down, I realized that, no matter what, I will need to change the code in every class that has a clickable view. But still, for the sake of future buttons what would be the best way to implement this behavior?
So far I tried: I created an interface called SoundyClickListener
which extends from OnClickListener
. There I implemented the onClick
method. But I couldn't get my head around on how to make a sound then the onClick
method gets called.