0

All. I am a new in android developing. Now I am working with TextView. As the case may be I set differnt text. But sometime text is very big. For example, I insert this "abcdefgh_myword", and i get something like that "abcdefg" in my small TextView, but i want to get this "..._myword". So i want to count the number of letters that i see (programly) and set text what i want to see. How to do this? Any ideas?

....

android:ellipsize="start" doesn't work how i want... Please watch what happen when i constrict width my TextView

before

enter image description here

after

enter image description here

<TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:ellipsize="start"
                android:gravity="center"
                android:maxLines="1"
                android:text="abcdef1234567" />

Any ideas?

4 Answers4

1

This could help you

android:ellipsize="start"
android:maxLines="1"

add it to the TextView in your XML file

EDIT:

According to this: https://stackoverflow.com/a/39890995/7325737 you have to use android:singleLine="true" because only end and marquee are supported with maxLines

Community
  • 1
  • 1
Hani
  • 104
  • 5
0

This would be only possible if you knew how wide each symbol is. Which you normally don't, as the font is system dependent.

You could use a monospaced font for this.

F43nd1r
  • 7,690
  • 3
  • 24
  • 62
0

You're probably looking for Java's string length() method. Check this answer. Then either use android:ellipsize="start" in XML or setEllipsize(TruncateAt.START); as needed.

Community
  • 1
  • 1
lidkxx
  • 2,731
  • 2
  • 25
  • 44
0

In addition to lidkxx 's answer you would call getText() on your text view to get the string.

TextView textview = (TextView) findViewById(R.id.your_text_view);
String s = textview.getText();
int letterCount = s.length();
drawinfinity
  • 315
  • 4
  • 21