Android: Playing sound when button clicked?
Posted
by gazeebo
on Stack Overflow
See other posts from Stack Overflow
or by gazeebo
Published on 2010-05-02T15:30:55Z
Indexed on
2010/05/02
15:37 UTC
Read the original article
Hit count: 243
android
Hi all,
I'm trying to play a sound file when a button is clicked but keeps getting an error.
The error is "The method create(Context, int) in the type MediaPlayer is not applicable for the arguments (new View.OnClickListener(){}, int)"
Here's my code:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Button zero = (Button)this.findViewById(R.id.btnZero);
zero.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mp = MediaPlayer.create(this, R.raw.mamacita_zero);
}
});
}
Any help or tips would be appreciated. Thnx!
© Stack Overflow or respective owner