问题
I'm using the Last.fm Java library that's listed in the "Downloads" section on the API. When I call "getWikiText()" and set it to my TextView, all the data is returned; however, the html isn't formatted correctly. Rather than showing separate paragraphs, the data is shown as one large text. To illustrate what I mean, here is a picture of what is being returned and then a link to the artist page of how things should look.
Picture - http://i.imgur.com/ameTO.jpg
How things should look - http://www.last.fm/music/Bon+Iver
This is what I'm calling to get the artist info, but what am I missing as to the paragraph spacing? I've search around quite a bit, but there's not much information on this in particular. I'm basically shooting in the dark at this point, so I need a little help.
artistInfo = Artist.getInfo("Bon Iver",key);
artistText = artistInfo.getWikiText();
info.setText("");
info.append(Html.fromHtml((artistText)));
回答1:
Do a simple replaceAll()
call is enough:
String artistText = artistInfo.getWikiText();
artistText = artistText.replaceAll("\n", "<br />");
info.setText(Html.fromHtml(artistText));
来源:https://stackoverflow.com/questions/9146469/how-can-i-read-breaks-in-downloaded-text