0

I want to make a dynamic webpage that can display my sqlite database's element in tabular format. How can I create a dynamic webpage in android? I make a static HTML page and put in assest folder. It works but now I want a dynamic webpage. Please help:

package com.Htmlview;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class Htmlview extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        WebView webview = new WebView(this);
        setContentView(webview);
        try {
            InputStream fin = getAssets().open("index3.html");
                byte[] buffer = new byte[fin.available()];
                fin.read(buffer);
                fin.close();
                webview.loadData(new String(buffer), "text/html", "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} 

This page works ... Help to make it dynamic through code.

gaurav gupta

2 Answers 2

2

Use java.text.MessageFormat:

  1. Put "{0}" markers in your html file.
  2. Read your html file into a string
  3. Create an arguments array from the database record
  4. Call MessageFormat.format(htmlString, dbArgs)
  5. Load the resulting string into the webview.
Sign up to request clarification or add additional context in comments.

2 Comments

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> </head> <body> <h1>It my page..testing!</h1> <table> <tr> <td>column</td> <td>column</td> <td>column1</td> <td>column1</td> </tr> <tr> <td>column11</td> <td>column11</td> <td>column11</td> <td>column11</td> </tr> </table> </body> </html> this is my html page
i want to set values in every column, but unable to do it,please help .thanks in advace
0

You can't modify the asset folder in runtime as it compiled at build time. So, you have 2 variants:

  1. You content from database as it is. Just read the bytes and pass them to the webview without storing to anywhere.

  2. Store the content to the file in internal memory and do like you did it with assets. But there is no sence as you already have your data in db.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.