How would I go about extracting a URL from a hyperlink when I click on it? There could be more than one URL link in the body of the text.
Asked
Active
Viewed 3,175 times
0
-
What you want to do by clicking on a text with multiple URLs? – Rohit Jun 13 '13 at 14:00
-
I have to read in the URL and basically get the id?=123123 out of it, and there are 3 or 4 different formats of the URL. one is www.abcxyz.com/id?=123123 or www.abcxyz.com/aricle/news/123123. Similar to that. So... I have to extract the URL text and run it through a function to get the id off of it. – DDukesterman Jun 13 '13 at 14:03
-
Is this something you are looking for: http://stackoverflow.com/questions/11101507/regular-expression-to-get-url-collection-from-string – Rohit Jun 13 '13 at 14:29
-
no.. i dont think that will work – DDukesterman Jun 13 '13 at 14:37
1 Answers
3
If I get your question correctly, so have different URL's in the text of your TextView
and you want to extract them first. Then you want to extract the parameters from each URL's. I think you are looking for something like getUrls() function in TextView. Here is how you can extract the URL's present in your textview:
URLSpan spans[] = textView.getUrls();
for(URLSpan span: spans) {
String sampleUrl = span.getURL();
Log.d(TAG, sampleUrl);
}
Using this you can get different URL's in form of String. Then using .split() function you can extract the query parameter.
See get Linkified text from textview-android...? question for more.
Hope this helps.

Community
- 1
- 1

Shobhit Puri
- 25,769
- 11
- 95
- 124