1
我在我的应用程序中有一个twitter feed,我试图通过在html中包装它们来改变hashtags,提及,链接等的外观。在Android ListView中显示Html
继承人是什么样子至今:
我的问题是,如何让我的列表视图识别的HTML标记?
这里是我的列表视图代码:
try{
Twitter twits = jsonToTwitter(result);
// lets write the results to the console as well
for (Tweet tweet : twits) {
// send the tweets to the adapter for rendering
listview = (ListView) getView().findViewById(R.id.listview);
textview = (TextView) getView().findViewById(R.id.text);
ArrayAdapter<Tweet> adapter = new ArrayAdapter<Tweet>(getActivity(), R.layout.listview_item, twits);
listview.setAdapter(adapter);
mProgressDialog.hide();
}
}catch(NullPointerException e){
mProgressDialog.hide();
System.out.println("No Network Available");
}
}
结束语的主题标记等,以html:
@Override
public String toString(){
Pattern mentionPattern = Pattern.compile("(@[A-Za-z0-9_-]+)");
Pattern hashtagPattern = Pattern.compile("(#[A-Za-z0-9_-]+)");
Pattern urlPattern = Patterns.WEB_URL;
StringBuffer sb = new StringBuffer(Text.length());
Matcher o = hashtagPattern.matcher(Text);
while (o.find()) {
o.appendReplacement(sb, "<b>" + o.group(1) + "</b>");
}
o.appendTail(sb);
Matcher n = mentionPattern.matcher(sb.toString());
sb = new StringBuffer(sb.length());
while (n.find()) {
n.appendReplacement(sb, "<font color=\"#657383\">" + n.group(1) + "</font>");
}
n.appendTail(sb);
Matcher m = urlPattern.matcher(sb.toString());
sb = new StringBuffer(sb.length());
while (m.find()) {
m.appendReplacement(sb, "<font color=\"#EDDA74\">" + m.group(1) + "</font>");
}
m.appendTail(sb);
return sb + "\n"+ getDateCreated() ;
}
不适用于我的实施,已经尝试过。 –
那么你的实现是什么?因为这就是你怎么做的。 – Guardanis
使用列表视图时,这种方式不正确。 –