4

I have a TextView and my need is to add 10 characters in that TextView by code. But when characters are greater than 10, they should be display in TextView but with 8 character + .. of that charsequence. And when I want to read text of that TextView I must get full charsequence not 8 character + .. . For example

tv.settext("ASDFGHJKLQ") // this is 10 characters long, so no rule required

but

tv.settext("ASDFGHJKLOP") // this is more than 10 characters then it should be display as ASDFGHJK.. in textView, but when I retrieve the value of textview, it should return ASDFGHJKLOP instead of ASDFGHJK.. , so how can it be done.

That textView is row of a listview.

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186

3 Answers3

5

Try adding this to your TextView (marquee or end):

android:ellipsize="marquee"

You may also need:

android:scrollHorizontally="true"

Without scrollHorizontally="true" you may still get the text wrapped rather than appended with ... I use these very 2 lines to display a list view in my app. The 3 long lines I have get appended correctly.

Bill Mote
  • 12,644
  • 7
  • 58
  • 82
  • You got down-voted too, even though your answer is right. weird. – Reno Mar 16 '11 at 15:13
  • Yeah. Usually competing answers make people mad. It's a silly game. You can throw a check mark on that if it worked and they can't undo that ;) – Bill Mote Mar 16 '11 at 17:04
4

This truncating happens because it does not fit in your list item. Reduce the font ?

or ellipsize ?

Community
  • 1
  • 1
Reno
  • 33,594
  • 11
  • 89
  • 102
  • I want truncating, but when I retrieve value, I must get original value not truncated .. – Pankaj Kumar Mar 16 '11 at 13:12
  • You want ellipsize. It does exactly what you're trying to do. It will truncate the display, but maintain the value. – Bill Mote Mar 16 '11 at 14:20
  • @Reno and @Bill Mote Thank you both. Its working and this is perfect answer for me. and I haven't option to check both answer to right, so I am giving up votes you. – Pankaj Kumar Mar 17 '11 at 06:13
1

I see only one solution. But maybe there are another solutions.

To store you string.

If string's length is greater than 10 letters set text of your TextView with 12345678..

And if you want to get right text you should take the value of the string and not of the textview.

Tima
  • 12,765
  • 23
  • 82
  • 125
  • It will not work for those text view, which are used as row of list view. – Pankaj Kumar Mar 16 '11 at 13:39
  • use the then an ArrayAdapter with ArrayList for you listview, so you can can get for every list item the right string and set the right value for every listview item – Tima Mar 16 '11 at 13:42