Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

java - Android make phone numbers clickable, autodetect

When I am using android on websites and reading emails, I notice that I can click on addresses to load into google maps, or click on phone numbers to call, or click on emails and send an email.

These elements on the web are formatted in a variety of ways, so there is some built in function that detects these sort of things.

How do I allow this within my app? I have a page which displays contact information in plain text and I would like the user to just be able to click.

Do I Absolutely need to create clicklisteners for each textview or is there a system function I just need to enable?

question from:https://stackoverflow.com/questions/6497327/android-make-phone-numbers-clickable-autodetect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Android has a utility expressly for this purpose: Linkify

TextView noteView = (TextView) findViewById(R.id.noteview);
noteView.setText(someContent);
Linkify.addLinks(noteView, Linkify.ALL);

See also: https://android-developers.googleblog.com/2008/03/linkify-your-text.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...