1

I have a header.html file & a footer.html file in my assets/html/ folder.

Here is my code to create and populate my WebView with content:

WebView contentView = (WebView) view.findViewById(R.id.contentView);
String contentText = Function.OBJECT.get("info").toString();

contentView.loadData(contextText, "text/html", null);

How do I wrap contextText with the header.html and footer.html and present the output in the WebView?

cwiggo
  • 2,541
  • 9
  • 44
  • 87

1 Answers1

0

if I understand you correctly, you want to parse header.html and footer.html and put some content in between.

By using WebView.loaddata() you're telling the WebView to use a String as content, but that's not what you want.

It's easiert to make an index.html, add a header/footer div, bind/append the content from header.html/footer.html via Javascript/Jquery to those divs (jquery append external html file into my page) and use WebView.loadUrl() to load your new index.html from the assets:

public class MainActivity extends ActionBarActivity {

private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (WebView) findViewById(R.id.activity_main_webview);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    String url  =("file:///android_asset/index.html");

    mWebView.loadUrl(url);
    }
}
Community
  • 1
  • 1
P. Stresow
  • 308
  • 3
  • 11