The following will provide the number of lines of text in the same place where you set tv.setText ().
int maxTextViewWidth="ENTER MAX WIDTH HERE"; tv.setText("hello\nhow are you?"); int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(maxTextViewWidth, View.MeasureSpec.AT_MOST); int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); tv.measure(widthMeasureSpec, heightMeasureSpec); int lineCount=tv.getLineCount();
galhe2
source share