Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a TextView to display text in one line in Android

I've set a TextView as the display. I want to display the operation being performed in one line, for example:

9856243187 + 2457896123 - 214583 

The problem is, when the input reaches the edge of the TextView - it jumps to the next line.

So, is there anyway to avoid this behavior and keep the input in one line, even if it goes out of the screen?

like image 554
Toni Joe Avatar asked Aug 01 '15 12:08

Toni Joe


People also ask

How do you add a line in TextView?

If you just want to add a line break in the form: textView. setText(string1+System. getProperty ("line. separator")+string2); then it works a treat, thank you!

How do I assign text to TextView?

Set The Text of The TextView You can set the text to be displayed in the TextView either when declaring it in your layout file, or by using its setText() method. The text is set via the android:text attribute. You can either set the text as attribute value directly, or reference a text defined in the strings.

What is the difference between text view and plain text in android Studio?

Textview : should be used for uneditable text which user wants to read but not to manipulate. e.g. News, Articles, Blogs. Plain text/ Edittext : should be used for taking user input in alphanumeric form. e.g. UserId, Comments.


1 Answers

You should use android:maxLines="1" in your TextView tag. android:singleLine="true" is deprecated.

like image 171
Copacel Avatar answered Sep 21 '22 20:09

Copacel