Question

I am developing an application that uses Spannable text from EditText. After using Html.toHtml() method for Spannable text it gives me this kind of String on the exit.

Подарок ко дню святого Валентина за 4 ночи и 1 день / Хабрахабр content: Пару недель назад, я решил подарить своей любимой на день святого Валентина подарок, изготовленный своими руками. Найденные в интернете самоделки мне не понравились, хотелось сделать что-то... annotation: “ add your comment here “

when original text was this:

Пару недель назад, я решил подарить своей любимой на день святого Валентина подарок, изготовленный своими руками. Найденные в интернете самоделки мне не понравились, хотелось сделать что-то...

This is the code that i use

contentView = (TextView)view.findViewById(R.id.contentPreview);
SpannableString contentText = (SpannableString) contentView.getText();
Log.e("Content Text",Html.toHtml(contentText));

Contentviews's code

<TextView
                    android:id="@+id/contentPreview"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:gravity="left"
                    android:layout_gravity="center"
                    android:text="Content"
                    android:bufferType="spannable"
                    android:textSize="16sp" />

My question is how can i normalize text i got from the TextView?

Thanks, Arshak

Was it helpful?

Solution

I found the solution. Looks like this was HTML Entity encoding, so for decoding you must Use Apache StringEscapeUtils.unescapeHtml4() method.

TextView contentView = (TextView)view.findViewById(R.id.contentPreview);
SpannableString contentText = (SpannableString) contentView.getText();
String htmlEncodedString = Html.toHtml(contentText);
String decodedString = StringEscapeUtils.unescapeHtml4(htmlEncodedString);

Log.e("Content Text",decodedString);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top