2

HTMLファイルを操作したいのですが、デプロイ時に実行しましたが、うまくいきません(入力HTMLページを表示する必要がありますが、デプロイ時にWebページが利用できないことを示しています)!エラーメッセージもログにありません!助けてください。私がやっている間違っているのはどこですか?

 public class TestActivity extends Activity {
    /** Called when the activity is first created. */
    WebView webView =null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webView =(WebView)findViewById(R.id.web);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl("file:///android-assets/www/index.html");

    }
}

ここに私のJavaScript。

function sayhello(){
alert("hi", document.getElementById('name'),value);
}

そしてhtmlファイルはここにあります

<!DOCTYPE html>
<html>
<head>
<script src="index.js"></script>
</head>
<body>
What is ur name  ?
<input id="name" value="">
<button onclick="sayhello()">say hello</button>
</body>
</head>
</html>

そしてレイアウト

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

    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/web"
        android:text="@string/hello" 
        />

</LinearLayout>
4

1 に答える 1

1

以下を使用する必要があります。

file:///android-asset/www/index.html

「s」を取り除くだけです

アップデート:

次の方法でページをロードすることもできます。

webView.loadDataWithBaseURL(null, html, "text/html", "utf-8",null);

2 番目のパラメータは、ロードするページです。

于 2012-09-17T18:35:04.463 に答える