4

Quite simple problem:

  1. I have some TextView

    TextView textView = (TextView) findViewById(R.id.textView1);
    
  2. I set styled text (with <b> tags or any other tags)

    textView.setText(Html.fromHtml("Simple text. <b>Bold text</b>. Simple text."));
    

Problem: when I call textView.getText() I receive Simple text. Bold text. Simple text.. <b> tags have disappeared somehow.

How can I retrieve text from TextView with its formatting?

3

1 Answer 1

8

@Wand Maker's assumption (see comments in question) was correct

Following code works:

TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText(Html.fromHtml("Simple text. <b>Bold text</b>. Simple text."), TextView.BufferType.EDITABLE);
String almostSameText = Html.toHtml(tv.getEditableText()).toString();

The result is: <p>Simple text. <b>Bold text</b>. Simple text</p>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.