0

I am using following code

LayoutInflater inflater = (LayoutInflater) getActivity()
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View innerView = inflater.inflate(R.layout.ac_image_list, null);

TextView tv = (TextView)  innerView.findViewById(R.id.tv_sorting);
tv.setText(Html.fromHtml(getString(R.string.sort_by_num_messages)));

The String sort_by_num_messages is defined as

<string name="sort_by_likes"><![CDATA[Sort by <b>Messages</b>]]></string>

The problem is that it is displayed as follows: Sort by < b >Messages< / b >

The code was working in an other activity there I was not using the LayoutInflator. The code is used in a SherlockFragment used as Tab.

tobias
  • 2,322
  • 3
  • 33
  • 53

2 Answers2

2

Get rid off the CDATA stuff and just quote the string like so:

<string name="sort_by_likes">"Sort by <b>Messages</b>"</string>
Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • I have now really strange behavior. I moved the code to a handler method. Now if I do it without CDATA it desplays "Sort by Messages" without bold. If I add again CDATA, I have the "Sort by Messages" with Messages bold. Can you explain this? – tobias Oct 18 '13 at 18:23
  • Is the line `tv.setText(Html.fromHtml(getString(R.string.sort_by_num_messages)));` still the same? Then I cannot explain that behavior. Sorry. – Ridcully Oct 19 '13 at 06:17
  • It is still the Same. – tobias Oct 19 '13 at 06:52
1

This is exactly what your code should display.
Anything inside <![CDATA[ ... ]]> should not be parsed and should show up exactly as you write it.

You can read more here: What is CDATA in html?

Community
  • 1
  • 1
mavrosxristoforos
  • 3,573
  • 2
  • 25
  • 40
  • wow. I wonder why it is working in my other activity? I use it the same way, simply without the inflator – tobias Oct 18 '13 at 14:50