Andreas Konstantakos Andreas Konstantakos - 6 months ago 13
Java Question

Play sound when typing in EditText in android application

Hi i am making an android application.
I want to play a default sound effect when i am typing in an EditText field.
Any ideas how to do that?

Thanks

Answer

you can use textwatcher for that purpose

 youredittext.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
          MediaPlayer mp = MediaPlayer.create(this, R.raw.yourmp3); // add mp3 file 
          mp.start();
            }
        });

Note : add yourmp3 in res->raw folder