Android Programming Tutorials

(Romina) #1

TUTORIAL 25


High-Priced Help


In this tutorial, we will extend our help system to embed user details, such


as their identi.ca screen name, in the help text itself on the fly, by way of


injecting Java objects into the WebView Javascript engine.


Step-By-Step Instructions........................................................................


First, you need to have completed the previous tutorial. If you are


beginning the tutorials here, or if you wish to not use your existing work,


you can download a ZIP file with all of the tutorial results, and you can copy


the 24-WebKit edition of Patchy to use as a starting point.


Step #1: Prep LunchList......................................................................


By default, WebView widgets have Javascript disabled. Since our current help


page does not use Javascript, that was not a problem in the previous


tutorial. Now, however, we are looking to add a script to the page, so we


need to enable Javascript in our WebView.


Add this line to onCreate() in HelpPage:


browser.getSettings().setJavaScriptEnabled(true);

That is all you need to enable basic Javascript operation.


257
Free download pdf