I am wanting to know if I can add some style to strings used in a list view? I have tried html formatting using escape codes and all I seem to get are the codes displayed but not actually doing what I desire. I would like to have the strings in the LISTVIEW to be bold then newline not bold and if possible a smaller size font. I currently have BOLD codes but that does not seem to do anything either and it does not give me any format errors.
ListView menuList = (ListView) findViewById(R.id.ListView_Menu);
String[] items =
{
getResources().getString(R.string.menu_item_one),
getResources().getString(R.string.menu_item_two),
getResources().getString(R.string.menu_item_three),
getResources().getString(R.string.menu_item_four),
getResources().getString(R.string.menu_item_five),
getResources().getString(R.string.menu_method_six),
};
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,
R.layout.menu_item, items);
menuList.setAdapter(adapt);
The strings look like this
<string name="menu_item_one"><b>This should be BOLD</b>\nSshould should not be be bold and smaller font if possible</string>
<string name="menu_item_two"><b>This should be BOLD</b>\nSshould should not be be bold and smaller font if possible</string>
<string name="menu_item_three"><b>This should be BOLD</b>\nSshould should not be be bold and smaller font if possible</string>
<string name="menu_item_four"><b>This should be BOLD</b>\nSshould should not be be bold and smaller font if possible</string>
<string name="menu_item_five"><b>This should be BOLD</b>\nSshould should not be be bold and smaller font if possible</string>
<string name="menu_item_six"><b>This should be BOLD</b>\nSshould should not be be bold and smaller font if possible</string>
Try using
getResources().getText()instead, and let your other variables be aCharSequence[]andArrayAdapter<CharSequence>. This should preserve the formatting you have in your XML declaration all the way through to the point where the text is set on the view in each list item.For clarity, I have rewritten your code sample in this fashion:
Hope that Helps!