Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView ellipsize and broken symbols

I have some problem with standard android ellipsize mechanism.

My textview xml layout is next:

<TextView
        android:id="@+id/something"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/message_test_text"
        android:lines="2"
        android:ellipsize="end"
        android:textColor="@drawable/dialogs_text_selector"
 />

Then in code I'm setting Helvetica typeface to this field. And then, in the end of second line I see broken symbol after dots:

Broken symbol

Because it used in list, I see a list of squares.

Can I remove it without tons of code?

Thank you!

like image 490
Roman Truba Avatar asked Jun 20 '12 09:06

Roman Truba


4 Answers

There is a issue logged here. Many people have some or the other problem when using TextView with ellipsize in a ListView. There are many workarounds that suggest changing the textview to single line, but you cant use that.

Try setting the android:maxLines="2" attribute.

Update:

Use TextUtils.ellipsize API to manually ellipsize the string before setting it to the textview. See whether the ellipsized string returned by this API contains the square char at the end.

Usage sample code:

TextPaint tp = new TextPaint();
tp.setTextSize(float textSize);
tp.setTypeface(Typeface typeface);
Charsequence elipText;
elipText = TextUtils.ellipsize ( text, tp, avail, TextUtils.TruncateAt.END);
textview.setText(elipText);
like image 102
Ronnie Avatar answered Oct 01 '22 05:10

Ronnie


The problem here I don't think it was your code. The problem is your .tff file which is missing the ellipsize character, hence the square is displayed. Your font was not... let's say mobile optimized.

like image 31
Ovidiu Latcu Avatar answered Oct 01 '22 03:10

Ovidiu Latcu


Class here solving problem very well

like image 21
Roman Truba Avatar answered Oct 01 '22 03:10

Roman Truba


Then in code I'm setting Helvetica typeface to this field

Hopefully you have paid for a license for this font. Otherwise, please do not distribute it.

And then, in the end of second line I see broken symbol after dots:

This has been covered before, such as: Android How to get rid of question mark at end of ellipsize

like image 31
CommonsWare Avatar answered Oct 01 '22 05:10

CommonsWare