I have a TextView that is X lines long. How do I get the text that is at, say, line 3?
Example: I have this TextView
Here is some code to supplement the accepted answer:
List<CharSequence> lines = new ArrayList<>();
int count = textView.getLineCount();
for (int line = 0; line < count; line++) {
int start = textView.getLayout().getLineStart(line);
int end = textView.getLayout().getLineEnd(line);
CharSequence substring = textView.getText().subSequence(start, end);
lines.add(substring);
}
You can use textView.getLayout().getLineStart(int line) and getLineEnd to find the character offsets in the text.
Then you can just use textView.getText().substring(start, end) -- or subsequence if you are using Spannables for formatting/etc.