0

In my Android project I have to show a spannable text in a text view. The text view is limited to two lines and I'm suppose to ellipsize it. But when I set the spannable string, it causes some problems if the string length exceeds two lines. When it exceeds two lines '...' which is suppose to appear is not showing. And further more it scrolls to the end of the text on touch text.

This is my text view in the layout

<TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="2"
    android:ellipsize="end" />

This is my code implementation

SpannableStringBuilder spannable = new SpannableStringBuilder(item.getText());
        spannable.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                openPost();
            }

            public void updateDrawState(TextPaint ds) {
                ds.setUnderlineText(false);
            }
        }, getText().length() - getNameLength(),getText().length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        notificationText.setText(spannable, TextView.BufferType.SPANNABLE);                
        notificationText.setMovementMethod(LinkMovementMethod.getInstance());

How can I fix this

Samantha Withanage
  • 3,811
  • 10
  • 30
  • 59
  • https://stackoverflow.com/questions/15627530/android-expandable-textview-with-animation – AskNilesh Mar 21 '18 at 11:28
  • @NileshRathod this question does not answer my question. Thing is this works pretty well with normal strings and starts not to perform as expected when using a spannable string which exceeds two lines. Any way, thanks in advance. – Samantha Withanage Mar 21 '18 at 11:52

0 Answers0