如何将数据插入到本地html表单并在webview

时间:2016-07-24 16:33:52

标签: android html webview

我想填写一个本地存储的简单html表单,数据通过意图传递,并在webview中显示我的html表单以便打印它。

我验证了意图中的数据传递给了我的活动,但是当我尝试加载数据时,我得到空字段。我做了以下几点:

Intent intent = getIntent();
    String name = intent.getStringExtra("ServiceName");

    InputStream is = null;
    try {
        is = getAssets().open("form.html");
    } catch (IOException e) {
        e.printStackTrace();
    }
    int size = 0;
    try {
        size = is.available();
    } catch (IOException e) {
        e.printStackTrace();
    }

    byte[] buffer = new byte[size];
    try {
        is.read(buffer);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    String str = new String(buffer);
    str = str.replace("textarea4", name);


    WebView wv = (WebView) findViewById(R.id.webView);

    wv.loadData(str, "text/html; charset=utf-8", "UTF-8");

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

所有这些都与html中的占位符有关,名称=" textarea4">详细信息我必须使用详细信息作为占位符而不是textarea4