Androider
Androider

Reputation: 445

SoundPool load method inside onclick

i want to load a SoundPool inside onClick, but when i use:

c = sound.load(this, R.raw.ak47s, 1);

I get an error: the method load in a SoundPool is not applicable for the arguments.

I know i can't use "this" inside load, so what to use ?

Upvotes: 0

Views: 443

Answers (2)

MByD
MByD

Reputation: 137322

If this is done in the Activity ExampleActivity, you should write:

c = sound.load(ExampleActivity.this, R.raw.ak47s, 1);

You need to fully-qualify this, as it is in an enclosed class instance.

Upvotes: 1

Navaneeth
Navaneeth

Reputation: 2584

use getApplicationContext() instead!

Upvotes: 0

Related Questions