我正在尝试使用正则表达式链接电话号码,但我无法将其应用于我的 setText();
我用谷歌搜索了很多,感觉我真的很接近成功。
我得到的代码:
if(tag.equals("Customer")) {
String name = xpp.getAttributeValue(null, separated_nodes[0].trim());
String number = xpp.getAttributeValue(null, separated_nodes[1].trim());
String SSNumber = xpp.getAttributeValue(null, separated_nodes[2].trim());
String Address = xpp.getAttributeValue(null, separated_nodes[3].trim());
String Postcode = xpp.getAttributeValue(null, separated_nodes[4].trim());
String City = xpp.getAttributeValue(null, separated_nodes[5].trim());
String Phone = "Phone#: " + xpp.getAttributeValue(null, separated_nodes[6].trim());
String Cell = xpp.getAttributeValue(null, separated_nodes[7].trim());
String Email = xpp.getAttributeValue(null, separated_nodes[8].trim());
// text.setText("Network "+xpp.getAttributeValue(null, "Name"));
Pattern pattern = Pattern.compile("[0]{1}[0-9]{6,15}");
Linkify.addLinks(text, pattern, "Phone#: ");
//Linkify.addLinks(text, pattern, xmlstring);
//Linkify.addLinks(text, pattern, Phone);
text.setText("Customer: \nName: " + name +"\n" +
"Customer Number: "+ number + "\n" +
"Social Security Number: "+ SSNumber +"\n" +
"Address: "+ Address +"\n" +
"Postal Code: "+ Postcode +"\n" +
"City: "+ City +"\n" +
""+ Phone +"\n" +
"Cellphone#: "+ Cell +"\n" +
"e-mail: "+ Email +"\n");
Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES) ;
}
如您所见,我尝试了多种方法来链接电话和手机号码。
我认为正则表达式是正确的。