Get status of single line

233 Views Asked by At

We can set single line with this

TextView textView = (TextView) view.findViewById(R.id.someTextView);
textView.setSingleLine(true);

But for get status of single line event getSingleLine() does not exit.

How can check that single line for text view is on (true) or off (false)?

My target API level is 15.

2

There are 2 best solutions below

2
On

You should use getMaxLines().

tv.setSingleLine( true ) || tv.setMaxLines( 1 );

int maxLines = tv.getMaxLines();

Assert.assertTrue( 1, maxLines );

The docs for setSingleLine() say that:

Sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input.

My undesrtanding of this, is that they are juts putting a nice wrapper around setMaxLines(1) and some others.

And under the covers, this method does indeed set the line count to 1.

6
On

I believe singleLine is deprecated, you should use textView.setMaxLines(1) instead and then use textView.getMaxLines() so to know if textViewis singleLine :

boolean isSingleLine = textView.getMaxLines() == 1;

EDIT FOR API 15

But in case you are using singleLine in that case to know if the TextView is singleLine you can use getTransformationMethod() available from API 1 onwards like so :

boolean isSingleLine = textView.getTransformationMethod() == SingleLineTransformationMethod.getInstance();