Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android :getting [OBJ] using Textview.SetText(characterSequence)

I am getting [OBJ] displayed on the screen when I try to set a ImageSpan on a text View..it shows a /uFFFC unicode character instead of the image on the screen,i.e. a dotted box with OBJ written inside it.

like image 720
Pratim Avatar asked Dec 19 '11 10:12

Pratim


People also ask

How to make Spannable text in android?

To apply a span, call setSpan(Object _what_, int _start_, int _end_, int _flags_) on a Spannable object. The what parameter refers to the span to apply to the text, while the start and end parameters indicate the portion of the text to which to apply the span.

How do I get TextView text?

String a = tv. getText(). toString(); int A = Integer. parseInt(a);

What is the use of setText in Android?

SetText(String, TextView+BufferType)Sets the text to be displayed using a string resource identifier.


1 Answers

I faced the same problem, thus I just wanted to have the HTML stripped and just get the String.

The solution is probably not the most beautiful one, but still pretty pragmatical:

public CharSequence stripHtml(String s) {
    return Html.fromHtml(s).toString().replace('\n', (char) 32)
        .replace((char) 160, (char) 32).replace((char) 65532, (char) 32).trim();
}

This [OBJ] character seemed to be (char) 65532.

I had to display a very ugly RSS item's (HTML) description field in a TextView without formats. The hypertext contained a lot of WYSIWYG debris like <p></p><p></p>

like image 52
klaus Avatar answered Sep 19 '22 15:09

klaus