开发者

By using Sqlite database How can i retrieve an html document using webview in android

How can i fetch an html document from sqlite tab开发者_如何学运维le using webview in android


If HTML for the document is written as a string in database, you can use regular projection(Select query) and obtain HTML using Cursor.


To displaye the SQLite Database output in the Webview to use the StringBuilder to enclose all needed output in HTML tags.

Example taken from the complete tutorial at http://www.androiddom.com/2011/06/android-and-sqlite.html :

StringBuilder builder = new StringBuilder();
builder.append("<html><body><h1>Headline</h1><table>");

c.moveToLast();
for(int i=c.getCount()-1; i>=0; i--) {

 // Get the data
 builder.append("<tr><td>");
 builder.append(c.getString(0));
 builder.append("</td><td>");
 builder.append(c.getString(1));
 builder.append("</td></tr>");

 // Move the cursor
 c.moveToPrevious();
}

builder.append("</table></html>");
webview.loadData(builder.toString(), "text/html", "UTF-8");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜