views:

342

answers:

1

Hi,

I'm using autoLink="web" attribute in TextView to launch Browser. However, I want to launch the myActivity with WebView, when I click the links in TextView. Is is possible that catch the click event and invoke startActivity?

Thanks in advance, Jason

+1  A: 

Yes, this is fairly easy to do :)

  • Create an activity with the WebView in it and the appropriate settings.
  • In the TextView, allow the links to fire an intent instead.
  • Make that intent one that opens the activity with the WebView in it
  • In that intent object, do myIntent.putExtra() and add the URL as an extra
  • In the WebView-containing activity, use savedInstanceState.getExtras() to retrieve the URL and load it in the WebView

You can get more information about intents and how to use them here:

http://developer.android.com/guide/topics/intents/intents-filters.html

You can also have a look here for the Notepad Tutorial application that contains some very basic examples of intents working.

HXCaine
Thankyou for your answer, T3Roar.but I cann't understand your second instruction "allow the link to fire an intent instead".Do you mean I don't need to do something for the textview?How can I make my own intent for the link in the textview to lanuch specific activity?
Jason Kim
Have a look at this article. His example called "ShowDialog" when links were pressed, but you can launch an intent there instead for your program. http://blog.elsdoerfer.name/2009/10/29/clickable-urls-in-android-textviews/
HXCaine