2、在Activity中实例化WebView
3、调用WebView的loadUrl( )方法,设置WevView要显示的网页
4、为了让WebView能够响应超链接功能,调用setWebViewClient( )方法,设置 WebView视图
5、用WebView点链接看了很多页以后为了让WebView支持回退功能,需要覆盖覆盖Activity类的onKeyDown()方法,如果不做任何处理,点击系统回退剪键,整个浏览器会调用finish()而结束自身,而不是回退到上一页面
6、需要在AndroidManifest.xml文件中添加权限,否则出现Web page not available错误。
<uses-permission android:name="android.permission.INTERNET"/>
javascript连接sqllite方法如下:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/htmlcharset=ISO-8859-1" http-equiv="content-type">
<title>Prova</title>
</head>
<body>
<script type="text/javascript">
//Provenia SRL ITC - Paola Savioli
//Questa funzione apre il database SQL Lite
//Il parametro che va cambiato è il nome del database
function ApriDatabase() {
try {
if (window.openDatabase) {
var shortName = 'Ristoranti.sqllite'
var version = '1.0'
var displayName = 'Ristoranti italia'
var maxSize = 65536// in bytes
db = openDatabase(shortName, version, displayName, maxSize)
}
} catch (e) {
alert('Apri Database' + e)
}
}
//Provenia SRL ITC - Paola Savioli
// Questa funzione eseque una query su un database aperto con la funzione ApriDatabase
function EseguiQuery($query, callback) {
try {
ApriDatabase()
if (window.openDatabase) {
db.transaction(
function (tx) {
tx.executeSql($query, [], function (tx, result) {
if (typeof (callback) == "function") {
callback(result)
} else {
if (callback != undefined) {
eval(callback + "(result)")
}
}
}, function (tx, error) {})
})
return rslt
}
} catch (e) {
alert('Esegui Query' + e)
}
}
function VisualizzaComuni() {
try {
var schemanode = document.GetElementById('RCOMUNI')
schemanode.innerHTML = ""
var result = EseguiQuery('SELECT * FROM COMUNE')
for (var i = 0i <result.rows.lenght++i) {
var row = result.row.item(i)
var notediv = document.createElement('div')
notediv.innerHTML = 'Codice Provincia:' + row['PROVINCIA'] + 'Nome:' + row['NAME']
schemanode.appendchild(notediv)
}
} catch (e) {
alert('Visualizza Comuni' + e)
}
}
</script>
<input type="button" name='select' onClick="VisualizzaComuni()"
value='Visualizza Comuni'>
<div id="RCOMUNI"></div>
</body>
</html>