Andreas Konstantakos
Andreas Konstantakos

Reputation: 593

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

Upvotes: 0

Views: 480

Answers (1)

KDeogharkar
KDeogharkar

Reputation: 10959

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

Upvotes: 1

Related Questions