first, depending on user's actions, want retrieve strings strings.xml resource file:
string option1 = context.getstring(r.string.string_one) string option2 = context.getstring(r.string.string_two) string option3 = context.getstring(r.string.string_three) then, pass these strings string[] options custom adapter listview set text of textview
public choicesadapter(context context, string[] options) { super(context, r.layout.choice_option_layout_2,choices); } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater myinflater = layoutinflater.from(getcontext()); view myview = myinflater.inflate(r.layout.option_list_layout, parent, false); string option = getitem(position); textview textview = (textview) myview.findviewbyid(r.id.textview); textview.settext(html.fromhtml(option)); return myview; } i want different strings in strings.xml file have different colors or different formatting. example, here 1 of strings:
<string name ="exit"><![cdata[<i>exit</i>]]></string> however, when string displayed on screen, shows as: "<i>exit</i>"
so, i'm guessing somewhere in method losing string.xml resource's formatting. how can instead of showing "<i>exit</i>", show "exit" on screen?
i thinking problem use .getstring(). somehow ignoring formatting added in .xml file?
check out http://developer.android.com/guide/topics/resources/string-resource.html#formattingandstyling - example is:
<string name="welcome">welcome <b>android</b>!</string> it says can use <b>text</b> bold text, <i>text</i> italic text, , <u>text</u> underlined text.
the important part of is, "normally, won't work because string.format(string, object...)method strip style information string. work-around write html tags escaped entities, recovered fromhtml(string), after formatting takes place."
they "store styled text resource html-escaped string" like
<string name="exit"><i>exit</i></string> and use:
resources res = getresources(); string text = string.format(res.getstring(r.string.exit)); charsequence styledtext = html.fromhtml(text); to formatted text correctly.
Comments
Post a Comment