user2730496
user2730496

Reputation:

Modify html file in android

I put the following code into the xml file of the layout.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F0E68C"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/heading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="ATTENDANCE STATS"
        android:textSize="35dp" />

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <Button
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:text="click me!"
        ></Button>
 </LinearLayout>

the webview displays a html file called table.html. Idid this in the java file of the activity as follows :

    WebView webView = (WebView) findViewById(R.id.webview);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("file:///android_asset/table.html");  

Now, I want to modify this html file from the java class of the activity, before loading it. How can I do this?

Upvotes: 0

Views: 1462

Answers (1)

laalto
laalto

Reputation: 152817

  1. Read HTML file from assets.

  2. Modify the HTML data in your app.

  3. Load the modified data to WebView with loadData() (or loadDataWithBaseURL()) instead of loadUrl().

Upvotes: 1

Related Questions