views:

66

answers:

2

This property makes

"short and very-long-word"

to

"short and"

. But I want to have smth. like

"short and very-lon..."

Right now I truncate the String in Java code. However, thats based on the number of characters and not the actual length of the link. So, the result isn't very nice.

String title;
    if(model.getOrganization().length() > 19) {
      title = model.getText().substring(0, 15).trim() + "…";
    } else {
      title = model.getText();
    }
    ((TextView) findViewById(R.id.TextViewTitle)).setText(title);

Update

Just noticed, this property actually adds "..." in a few cases. But not in all of them:

12345678901234567890 becomes "12345678901234..."

However,

"1234567890 1234567890" becomes "1234567890" and not "1234567890 123..."

Update 2

Now it really gets funky! I just set singleLine=true and removed maxLine (The bug appears with and without setting ellipsize attribute)...

alt text

This is a screenshot take from Motorola Milestone with android 2.1 update 1. Same happens on HTC Desire with the same android version

Update 3

Now I use android:ellipsize="marquee". That seems to be the only properly working setting. It's also only moving, when focused. I see it in many other apps also. I guess its common practise.

A: 

I had a similar problem and setting this property to the TextView helped:

android:singleLine="true"

Also, I was using a RelativeLayout so I limited the space the TextView could take by setting a left margin to a button to the right of the TextView, so that the text cannot expand further and is forced to truncate its content.

Maybe it's not the solution to your problem, but it helped me in a similar situation.

Maragues
Didn't help in my case. By the way "singleLine" is deprecated. I don't have to set margins, it is already tuncating, but not very nice.
OneWorld
check this question: http://stackoverflow.com/questions/1698881/cant-get-ellipsis-to-work-on-android I know singleline is deprecated, read the comments in the bug page from the linked question and you'll see why I'm using it.
Maragues
See Update 2 above
OneWorld
A: 

Maybe you could take a look at how the private Ellipsizer class used by the OS works and modify it for your app?

Josh
OK, thank you! Are there any less time consuming suggestions?
OneWorld