piu
piu

Reputation: 43

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

How can i fetch an html document from sqlite table using webview in android

Upvotes: 0

Views: 204

Answers (2)

Ranbir
Ranbir

Reputation: 81

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");

Upvotes: 0

Samuh
Samuh

Reputation: 36484

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

Upvotes: 1

Related Questions