First, depending on the user's actions, I want to retrieve a certain strings from my 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, I pass these strings as String[] options to a custom adapter for a ListView
where I set the text of a 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 my strings.xml file to have different colors or different formatting. For example, here is one of my strings:
<string name ="exit"><![CDATA[<i>exit</i>]]></string>
However, when this string is displayed on the screen, it shows as: "<i>exit</i>"
So, I'm guessing somewhere in my method I am losing the string.xml resource's formatting. How can I get it so instead of showing "<i>exit</i>", it will show "exit" on the screen?
I am thinking my problem is where i use .getString(). Is this somehow ignoring the formatting that I added to it in the .xml file?