Search code examples
androidbuttonaudiosoundpool

Android: button plays 2 sounds onClick


I have a GridView with buttons. I have edited the GridView.onItemClickLisener to play a sound when a button is clicked:

mGridView.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long arg3) {
                        Button button = (Button) view;
                        button.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                        mSoundPoolHelper.play(mSoundId);
                    }
                });

However, when I click the buttons I can listen two different sounds. One is mSoundId, set up in the listener. But additionally, I can listen the Android default button click sound. If I turn down the media volume, then I can only listen to the Android default button click sound. How can I remove this sound?


Solution

  • If you want to disable the Button default click sound, then use the following code,

    yourbutton.setSoundEffectsEnabled(false);
    

    Also you can disable default sound throughout your Application by changing in your theme.Refere below post for this,

    https://stackoverflow.com/a/14763254/1564821

    Disable Button click sound in android