How can I create inline hyperlinks in a TextView while having different values for the link URL and link text?
How can I create inline hyperlinks in a TextView while having different values for
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do this by using the SpannableString stuff that Android has. Specifically, you can attach a URLSpan to whatever text you want and set the URL to an arbitrary URL. Just create a SpannableString (or SpannableStringBuilder if you’re composing several strings), attach a URLSpan using setSpan and then put that in the TextView. Note that you have to call setMovementMethod to an instance of LinkMovementMethod otherwise the clicks won’t work. Oh, and don’t try and have an onClick handler on the TextView as well, you’re going to get very frustrated if you try and do that.