2

javascriptからいくつかの値を受け取るためのjavascriptインターフェースクラスがあります。インターフェイス クラスからその値をトーストしましたが、その値を TextVie に設定することはできません。何が問題になりますか??

 class JavaScriptInterfaceForCount {
    Context mContext;

    JavaScriptInterfaceForCount(Context c) {
        mContext = c;
    }
    public void receiveValueFromJs(String scrollwidth, String columwidth) {
            mPagenumberTextView.setText(scrollwidth+"");
      }
 }

Logcat の結果

06-08 16:20:37.003: E/AndroidRuntime(1198):                android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created     a view hierarchy can touch its views.
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:254)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.view.View.requestLayout(View.java:8125)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.checkForRelayout(TextView.java:5378)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.setText(TextView.java:2688)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.setText(TextView.java:2556)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.widget.TextView.setText(TextView.java:2531)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at com.epub.reader.TestWebActivity$JavaScriptInterfaceForCount.receiveValueFromJs(TestWebActivity.java:326)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:245)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1562)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore.access$1400(WebViewCore.java:52)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:948)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.os.Looper.loop(Looper.java:123)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:621)
06-08 16:20:37.003: E/AndroidRuntime(1198):     at java.lang.Thread.run(Thread.java:1096)
4

1 に答える 1

6
runOnUiThread(new Runnable() {
     public void run() {
         mPagenumberTextView.setText(scrollwidth+"");
    }
});

メインスレッドでUIを編集する必要があります

于 2012-06-08T11:16:49.703 に答える