Urbanleg
Urbanleg

Reputation: 6532

EditText - On word wrap (new line) listener

Is there a way to listen on an EditText for the scenario where the text inserted is being wraped? (standard new line listener won't work since there is actually no real "/n" string on the edittext).

Maybe a listener on the height of the edit text changing?

Upvotes: 4

Views: 940

Answers (1)

Tony
Tony

Reputation: 2451

Try this. Depending on the number of lines you know if there is text wrapping or not.

edittext.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {}

        public void beforeTextChanged(CharSequence s, int s, int c, int a) {}

        public void onTextChanged(CharSequence s, int s, int b, int c) {
            Log.d("TESTING", " LINES = " + edittext.getLineCount());
        }
    });

Upvotes: 7

Related Questions