7

I have a TextView which i set the text using setText(). In properties, I have set:

Ellipsize = END
Lines = 1
Gravity = Left
Scroll Horizontal = False

But this clips extra text (clips text since where last space is found). But do not include dots ("...") at the end.

Example:

-------------------------------
|                             |
 Hi how are you ? And where are you now ?
|                             |
|                             |

After clipping:

-------------------------------
|                             |
 Hi how are you ? And where 
|                             |
|                             |

What I want:

-------------------------------
|                             |
 Hi how are you ? And where...
|                             |
|                             |

I am using Android 1.6. Plz help.

Vpp Man
  • 2,384
  • 8
  • 43
  • 74

4 Answers4

15

android:singleLine="true" and textView.setEllipsize(TruncateAt.END);

These are the two key elements to achieve that.

Arpit Garg
  • 8,476
  • 6
  • 34
  • 59
  • i donot understand. When i set SingleLine = TRUE, it works. But it is depreciated !!! – Vpp Man Apr 02 '12 at 18:30
  • 1
    no it's not deprecated.. as the ellipsize works when our textview has single line enables or the max lines are set for that.. – Arpit Garg Apr 02 '12 at 18:32
  • thanku. But still I donot know. In properties window this SingleLine is listed below "Depreceated" in my Eclipse ! – Vpp Man Apr 02 '12 at 18:37
  • 1
    you can also set the ellipsize in the xml: android:ellipsize="end" – whoabackoff Apr 27 '12 at 20:24
  • @PratikButani The ellipsize works on 4.0 also.I tested it it's working – Arpit Garg Apr 02 '13 at 14:18
  • @ArpitGarg I have given android:lines="1" android:scrollHorizontally="true" android:ellipsize="end" then also not work for me.... how you have given?? – Pratik Butani Apr 03 '13 at 04:39
  • @PratikButani The android:scrollHorizontally="true" is different aspect, it is intended to auto-scroll. The text auto scroll won't work in 4.0 and up. The question was just to have ellipse size(...) at end of text view not auto-scroll. Your requirement is different to the question and answer suggested. – Arpit Garg Apr 03 '13 at 05:35
  • @ArpitGarg Ya i have removed it then also it will not work for me. Last char of string is displaying in second line if string is bigger than textview... – Pratik Butani Apr 03 '13 at 06:06
  • @PratikButani make sure to give android:singleLine="true" with width fill_parent , why is it going in next lines – Arpit Garg Apr 03 '13 at 06:09
  • Hey @ArpitGarg, Its working for me in Textview. Thanks. But now i want to do for Tab in TabActivity. Please Help me for that – Pratik Butani Apr 03 '13 at 06:30
  • instead of android:singelLine="true", you can use android:maxLines="1". that is not deprecated. – Ali Mehrpour Sep 12 '14 at 18:59
3
        android:singleLine

is deprecated.

Here is what the documentation says:

"This attribute is deprecated and is replaced by the textMultiLine flag in the inputType attribute. Use caution when altering existing layouts, as the default value of singeLine is false (multi-line mode), but if you specify any value for inputType, the default is single-line mode. (If both singleLine and inputType attributes are found, the inputType flags will override the value of singleLine.). [boolean]"

To solve your problem. You can use the following:

        android:ellipsize="end"
        android:maxLines="1"
JaydeepW
  • 3,237
  • 1
  • 25
  • 27
2

Textview has a property call singleLine make it true in your XML file.

If you are doing through code then

textView.setSingleLine(true);
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
1

here work for me

android:ellipsize="end"
android:singleLine="true"
Scott.N
  • 172
  • 2
  • 17