Problem with TextView setText

I have a TextView , and I need to add 10 characters to the TextView by code. But when characters are more than 10, they should be displayed in the TextView, but with 8 character + .. this charsequence. And when I want to read the text of this TextView, I have to get a full charsequence of not 8 character + .. for instance

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

but

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

This text is a list box.

+4
source share
3 answers

Try adding this to your TextView (selection area or end):

 android:ellipsize="marquee" 

You may also need:

 android:scrollHorizontally="true" 

Without scrollHorizontally = "true", you can still get the text wrapped, not the attached ... I use these two lines to display a list in my application. I got 3 long lines correctly.

+5
source

This truncation occurs because it does not match your list item. Decrease the font?

or ellipsis ?

+4
source

I see only one solution. But perhaps there are other solutions.

To save the string.

If the string is longer than 10 letters, set the text of your TextView with 12345678 ..

And if you want to get the correct text, you should take the value of the string, not the text.

+1
source

Source: https://habr.com/ru/post/1343920/


All Articles