Android 用数据填充HTML页面

Android 用数据填充HTML页面,android,html,Android,Html,我有一个ListView,每个项目在单击后返回相同的WebView类。我想用作为参数传递的代码填充HTML页面中的一些字段,以创建具有相同结构的不同内容 我的网页有如下代码: h2 {color: %@;} section#title {background-color: %@;} section#video a { color: %@; } section#formation a { color: %@; } <h1>%@</h1> <p class="type

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

我的网页有如下代码:

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

<h1>%@</h1>
<p class="type-metiers">%@</p>
h2{color:%@;}
第#节标题{背景色:%@;}
第#节视频a{颜色:%@;}
第#组a{颜色:%@;}节
%@

%@


因此,我需要替换HTML文件的每个
%@
。如何执行修改外部文件内容的循环?

将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;
}

听起来不错,谢谢!但我必须在同一页中用不同的值替换%@。添加了一个解决方案,以便您可以输入不同的值