Книга: Beginning Android

Loading It Up

Loading It Up

There are two main ways to get content into the WebView. One, shown earlier, is to provide the browser with a URL and have the browser display that page via loadUrl(). The browser will access the Internet through whatever means are available to that specific device at the present time (WiFi, cellular network, Bluetooth-tethered phone, well-trained tiny carrier pigeons, etc.).

The alternative is to use loadData(). Here, you supply the HTML for the browser to view. You might use this to

• display a manual that was installed as a file with your application package

• display snippets of HTML you retrieved as part of other processing, such as the description of an entry in an Atom feed

• generate a whole user interface using HTML, instead of using the Android widget set

There are two flavors of loadData(). The simpler one allows you to provide the content, the MIME type, and the encoding, all as strings. Typically, your MIME type will be text/html and your encoding will be UTF-8 for ordinary HTML.

For instance, if you replace the loadUrl() invocation in the previous example with the following code, you get the result shown in Figure 13-2.

browser.loadData("<html><body>Hello, world!</body></html>",
 "text/html", "UTF-8");


Figure 13-2. The Browser2 sample application

This is also available as a fully-buildable sample, as WebKit/Browser2.

Оглавление книги


Генерация: 0.202. Запросов К БД/Cache: 2 / 0
поделиться
Вверх Вниз