我正在尝试使用正则表达式链接phonenumbers,但我无法将其应用于我的setText();
我用Google搜索了很多,感觉就像我真的很接近成功。
我得到的代码:
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) ;
}
如您所见,我尝试了多种方式来连接手机和手机号码。
我认为RegEx是正确的。
答案 0 :(得分:1)
Linkify.addLinks()
在设置文字视图后,您之前就是这样做了Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS)
?更新
此外,在这里:Linkify.addLinks(text, pattern, "Phone#: ");
第三个参数应该是Scheme
,“Phone#:”不是有效的方案。它应该是tel:
。
答案 1 :(得分:0)
不幸的是,打电话给
Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES)
最后一行的是擦除先前调用Linkify.addLinks()创建的Spannables。请参阅Linkify Documentation