Beep Sound when editext Character limt exceeds in android
<p>I'm begginer in android, How to play beep sound when charecter limit exceeds in edittext, i have tried by Setting addTextChangeListener but it wont get event after limit exceed so cant play sound and onKeylistener is only works on physicle keys so please give me any hints to solve the problem.</p>

<p>This is my code</p>

<p>private EditText editTextBox;
    private MediaPlayer mMediaPlayer;
    private int len;
    private int limit = 10;</p>

<pre><code>public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // setContentView(new EditText(this));

    setContentView(R.layout.main);
    editTextBox = (EditText) findViewById(R.id.EditTextBox);

    editTextBox.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            if (s.length() &gt; 10) {
                playAudio();
            }
            if (s.length() == limit) {
                len = limit + 1;
            } else {
                len = s.length();
            }
            Log.e("beep", "onTextChanged" + " " + count);
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            Log.e("beep", "beforeTextChanged");
        }

        public void afterTextChanged(Editable s) {
            Log.e("beep", "afterTextChanged");
        }
    });
    editTextBox.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            Log.e("beep", "onKeyListener" + " " + len);
            if (len == limit + 1) {
                len++;
            } else {
                if (len &gt; limit) {
                    if (!(keyCode == KeyEvent.KEYCODE_DEL))
                        playAudio();
                }
            }
            Log.e("beep", "onKeyListener");
            return false;
        }
    });

}

private void playAudio() {
    try {

        mMediaPlayer = MediaPlayer.create(this, R.drawable.beep1);
        mMediaPlayer.setLooping(false);
        Log.e("beep", "started0");
        mMediaPlayer.start();
        Log.e("beep", "started1");
        mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
            public void onCompletion(MediaPlayer arg0) {
                // finish();
                stopAudio();
            }
        });
    } catch (Exception e) {
        Log.e("beep", "error: " + e.getMessage(), e);
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    stopAudio();
}

private void stopAudio() {
    if (mMediaPlayer != null) {
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
}
</code></pre>

<p>Thanks in advance</p>
