If I have a textview with spanned text obtained from Html.fromHtml(source), how to make the textview to react when I click on a link? In my textview, link is something like "click here" and this text is a link, it's not a direct link like www.google.com.
2
- it seems that this is an android os bug. code.google.com/p/android/issues/detail?id=2219Buda Gavril– Buda Gavril2011-03-22 15:29:52 +00:00Commented Mar 22, 2011 at 15:29
- [Click this one, it's good for you][1] [1]: stackoverflow.com/questions/4790746/links-in-textview/…sonida– sonida2013-07-11 06:35:37 +00:00Commented Jul 11, 2013 at 6:35
Add a comment |
4 Answers
android:autoLink="web" 1 Comment
Derzu
Yes it works. Put that on your TextView, and android:linksClickable="true"
1 Comment
Buda Gavril
but my source code contains html tags... So, to use linkify, I need to get rid manually of these tags and linkify manually all ex link tags... isn't there a simple way?
I guess you want to handle span click event by yourself.
There two ways for this:
1)Create new class extends URLSpan
2)Create new class extends LinkMovementMethod
Please see below url, may be help you.
https://stackoverflow.com/a/16182500/596555
Comments
Add this to your tetView
android:text="@string/Documentation Add this line to string.xml [ res/values]
<string name="Documentation"><a href="https://developer.android.com/guide/components/activities/activity-lifecycle">Android Activity Lifecycle Documentation</a> </string> Add This code to your MainActivity.java
TextView textView = findViewById(R.id.textView); textView.setMovementMethod(LinkMovementMethod.getInstance());