Reputation: 43
How can i fetch an html document from sqlite table using webview in android
Upvotes: 0
Views: 204
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
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