我试图用正则表达式来linkify PHONENUMBERS,但我不能设法把它在我的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) ;
}
正如你看到的,我已经尝试了多种方法来linkify电话和手机号码。
我认为,正则表达式是正确的。