get Linkified text from textview-android…?

强颜欢笑 提交于 2019-12-10 15:15:55

问题


I have a textview in my android application.

    textView.setText(message);
    Linkify.addLinks(textView, Linkify.ALL);

with this code it identify phone number,email address, weblink etc. and highlight it for click, so appropriate intent call.

I want to fetch whatever linkify in my textview store it in an array example

if my textview contains "Hello, this is deer, my phone number is 9988776655 and email id is abc@gmail.com and weburl is www.abc.com" string

then I want to fetch "9988776655","abc@gmail.com","www.abc.com" and store it in array, is it possible...!?!


回答1:


You can use TextView#getUrls after the call to Linkify like this:

URLSpan spans[] = textView.getUrls();
for(URLSpan span: spans) {
    Log.d(TAG, span.getURL());
}



回答2:


use textView.getUrls() . Then loop over this array and use URLSpan.getUrls() to get individual link



来源:https://stackoverflow.com/questions/11735725/get-linkified-text-from-textview-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!