I have textview which I need to linkify. Here's what I am doing..
TextView text = (TextView) view.findViewById(R.id.name); text.setText("Android...Update from Android"); Pattern pattern = Pattern.compile("Android"); String scheme = "www.android.com"; Linkify.addLinks(text, pattern, scheme);
The text-view is displayed correctly with the text "Android...Update from Android", but I am facing two problems.
1) My text string has two instances of the string "Android". So, both the text are linkified. I want only the first occurrence to be linkified. How should I go about it?
2) When I click the linkfy text, it opens the browser, but the URL is weird. The url it tries to open is "www.comandroid". I don't know whats going wrong here. The text "android" in the URL is being replaced. Am I doing something wrong when Linknifying the text.
Any help will be highly appreciated.
Linkify take a piece of text and a regular expression and turns all of the regex matches in the text into clickable links. This is particularly useful for matching things like email addresses, web URLs, etc. and making them actionable.
To call linkify in android, we have to call linkify. addLinks(), in that method we have to pass textview and LinkifyMask. Linkify. WEB_URLS: It going make URL as web url, when user click on it, it going to send url to default web browsers.
The easy way is put autoLink in XML layout.
android:autoLink="web"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With