本文介绍了Linkify使用正则表达式电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用常规的前pressions到linkify PHONENUMBERS,但我不能设法把它在我的setText();
我已经很多一派,感觉像IM真的接近成功。
在code我得到:
如果(tag.equals(客户)){
字符串名称= xpp.getAttributeValue(NULL,separated_nodes [0] .trim());
字符串数= xpp.getAttributeValue(空,separated_nodes [1] .trim());
串SSNumber = xpp.getAttributeValue(空,separated_nodes [2] .trim());
串地址= xpp.getAttributeValue(空,separated_nodes [3] .trim());
后弦code = xpp.getAttributeValue(NULL,separated_nodes [4] .trim());
串市= xpp.getAttributeValue(空,separated_nodes [5] .trim());
串电话=电话号码+ xpp.getAttributeValue(NULL,separated_nodes [6] .trim());
串细胞= xpp.getAttributeValue(空,separated_nodes [7] .trim());
字符串email = xpp.getAttributeValue(NULL,separated_nodes [8] .trim());
// text.setText(网络+ xpp.getAttributeValue(NULL,姓名));
模式模式= Pattern.compile([0] {1} [0-9] {6,15});
Linkify.addLinks(文字,图案,电话号码:);
//Linkify.addLinks(text,图案的xmlString);
//Linkify.addLinks(text,模式,电话); text.setText(客户:\\ n名称:+姓名+\\ n+
客户编号+数字+\\ n+
社会安全号码+ SSNumber +\\ n+
地址:+地址+\\ n+
邮政code:+邮报code +\\ n+
城市:+城市+\\ n+
+电话+\\ n+
手机#:+电池+\\ n+
电子邮件:+电子邮件+\\ n); Linkify.addLinks(文字,Linkify.EMAIL_ADDRESSES);
}
正如你所见,香港专业教育学院尝试了多种方法来linkify电话和手机号码。
我觉得正则表达式是正确的。
解决方案
- 您需要调用
Linkify.addLinks()
后,您必须设置您的文本视图,你 之前做 - 不Linkify已经支持的电话号码,例如
Linkify.addLinks?(文字,Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS)
的更新的
此外,在这里: Linkify.addLinks(文字,图案,电话号码:);
第三个参数应该是方案
,电话号码:不是一个有效的方案。它应该是电话:
I am trying to linkify phonenumbers using regular expressions, but i cant manage to apply it on my setText();
I've googled alot and it feels like im really close to success.
The code i got :
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) ;
}
As you see, ive tried multiple ways to linkify Phone and Cellphone-number.
I think the RegEx is correct.
解决方案
- you need to call
Linkify.addLinks()
AFTER you have set up your text view, you're doing it before - Doesn't Linkify already support phone numbers, e.g.
Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS)
?
Update
Also, in here: Linkify.addLinks(text, pattern, "Phone#: ");
the third argument is supposed to be the Scheme
, "Phone#:" is NOT a valid scheme. It should be tel:
.
这篇关于Linkify使用正则表达式电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!