用数据填充HTML页面

时间:2013-06-04 10:00:34

标签: android html

我有一个ListView,每个项目在单击后返回相同的WebView类。我想填充HTML页面中的一些字段,并将代码作为参数传递,以创建具有相同结构的不同内容。

我的网页上有这样的代码:

h2 {color: %@;}
section#title {background-color: %@;}
section#video a { color: %@; }
section#formation a { color: %@; }

<h1>%@</h1>
<p class="type-metiers">%@</p>

所以我需要替换HTML文件的每个%@。如何进行修改外部文件内容的循环?

1 个答案:

答案 0 :(得分:0)

将HTML中的文本放在字符串中,将正则表达式应用于字符串。

String s = html.toString();
String replaceWith = "Put something in this string";

source.replaceAll("%@", replaceWith);

如果要替换为不同的值,可以使用Pattern / Matcher

String s = html.toString();

Pattern p = Pattern.compile("%@");
Matcher m = p.matcher(s);
while (m.find()) { 
    // Find each match in turn; 
    // Process your findings here;
}
相关问题