2016-07-24 73 views
0

我想填充本地存儲的簡單html表單,其中包含意圖傳遞的數據並在webview中顯示我的html表單以便打印它。如何將數據插入到本地html表單並在webview上顯示

我驗證了意圖數據傳遞給我的活動,但是當我嘗試加載數據時,我得到空字段。我做了以下事情:

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"); 

我在這裏失蹤了什麼?

+0

'海峽= str.replace( 「textarea4」,名);'。我們當然不知道這是否有效。你應該顯示完整的輸入。 – greenapps

回答

0

它所需要做的與HTML中的佔位符,NAME = 「textarea4」>詳細信息我不得不使用詳情的佔位符不textarea4

相關問題