Lukap
Lukap

Reputation: 31973

Limit the size of the textview horizontally

I have this text view

<TextView android:id="@+id/name"
          android:singleLine="true"
          android:layout_height="wrap_content"
          android:textColor="#ffffff" 
          android:textSize="16sp"  
          android:layout_width="fill_parent"/>

The problem is if the text is bigger then the textview can display it just stop displaying it looks something like this |some unfinished tex| I want to have dots on the end in this way it will be more clear to the user that this is unfinished and it it is displayed only a part of the text

I would prefer something like this |Some unfinished te..|

How to implement this ?

Upvotes: 3

Views: 2495

Answers (3)

Pradeep Sharma
Pradeep Sharma

Reputation: 35

you can do this type;

public String getChar(String inputstring){
String substring;
if(inputstring.length() >0 ){
substring=inputstring.substring(int beginIndex, int endIndex);
}
StringBuilder sb=new StringBuilder(substring);
sb.append("....");
return sb.tostring();
}

Upvotes: 0

Hiral Vadodaria
Hiral Vadodaria

Reputation: 19250

I used the hack by checking text size every time i set it to textview and appended those dots after a substring of text.I don't know it is bad practice or so!! :P

Upvotes: 0

Mariusz Jamro
Mariusz Jamro

Reputation: 31692

Have you tried setting android:ellipsize paremeter to "end"?

Upvotes: 7

Related Questions