How to search a word and replace it with a hyperlink of same word
In my app, I have stored list of words in one string array and their definitions in another array in strings.xml. I want to underline the words if any of the definitions contains other word. So before this activity, in the background what I did, for e开发者_如何学Pythonvery description , i searches the array of word list, if it matches replace the word with a hyperlinked word.
And on click of the word, it should it should go to word with corresponding definition. The activity contains 2 text views, one with word and definitions. How can I do that? Please help ..
android.text.util.Linkify is your friend. It will search for occurence of string, using some match filter, of which implementation is up to you. Then it will produce Spannable string containing clickable spans (hyperlinks). To display the result, you can use for example WebView, but for displaying Spannable in WebView, you must first convert it to Html using android.text.Html.toHtml(), then display it as html text.
if you want your text view to be clickable and to open the url you need to add this property android:autoLink="web"
精彩评论