Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the TextView maxLines programmatically?

I'm having a hard time reseting the maxLines attribute of a TextView programmatically.

Just tried setting to 0 and it doesn't work. -1 crashes the application. I could use a simpler workaround and set the maxLines to 5000 but I don't want to do that.

Any ideas how to do that?

UPDATED

Well, I've found one problem.. I've set the Ellipsize as well... I'm just going to use the following workaround:

TextView questionDetail = (TextView) mQuestionDetailHeader.findViewById(R.id.desc);  questionDetail.setText(mCurrentQuestion.getQuestion()); questionDetail.setMaxLines(Integer.MAX_VALUE); //As in the android sourcecode questionDetail.setEllipsize(null); 
like image 686
Valdemar Avatar asked Jun 22 '11 10:06

Valdemar


People also ask

How do I know if Textview Ellipsized?

null){ int lines = l. getLineCount(); if ( lines > 0) if ( l. getEllipsisCount(lines-1) > 0) Log. d(TAG, "Text is ellipsized"); } } });


1 Answers

As there isn't yet an approved answer - the proper way to reset the maxlines property of the TextView is:

textView.setMaxLines(Integer.MAX_VALUE);

As per Valdemar's comment and this stackoverflow answer. Using -1 will cause an ArrayIndexOutOfBoundsException.

Keep in mind only END and MARQEE setEllipsize() settings will be respected for maxlines >= 2 according to the documentation:

If setMaxLines(int) has been used to set two or more lines, END and MARQUEE* are only supported (other ellipsizing types will not do anything).

like image 199
alexgophermix Avatar answered Oct 06 '22 09:10

alexgophermix