Search code examples
androidtextview

Is it possible to know the number of visible words? not full length?


Is it possible to know the number of visible words? not full length?

I add to textView string from 100 words. But visible only 10 words. How do I know that only 10 words?

Log.e("asdas", String.valueOf(messageView.length()));

not working

Sorry if this question is too complex :((


Solution

  • I don't know WHY you need this, but here it goes:

    int start = textView.getLayout().getLineStart(0);
    int end = textView.getLayout().getLineEnd(textView.getLineCount() - 1);
    String displayed = textView.getText().toString().substring(start, end);
    int visibleWords = displayed.split(" ").length