class JavaScriptInterface {
private TextView contentView;
public JavaScriptInterface(TextView aContentView) {
contentView = aContentView;
}
@JavascriptInterface
public void processContent(String aContent) {
final String content = aContent;
contentView.post(new Runnable() {
public void run() {
contentView.setText(content);
contentView.setTextColor(Color.DKGRAY);
}
});
}
}
TextView tv2 = (TextView) findViewById(R.id.source);
JavaScriptInterface jv = new JavaScriptInterface(tv2);
webview1.addJavascriptInterface(jv, "INTERFACE");
webview1.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(final WebView view, String url) { view.loadUrl("javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);");
}
});
webview1.loadUrl("javascript:document.getElementById('txtuName').value='"+s_ogrNo+"'");
webview1.loadUrl("javascript:document.getElementById('txtUPassGorunen').value='"+s_parola+"'");
webview1.loadUrl("javascript:document.getElementById('txtSecCode').value='"+s_captcha+"'");
webview1.loadUrl("javascript:document.getElementsByName('btnLogin')[0].click();");
String tviewtext = tv2.getText().toString();
// i can see source code on textview, but i can't getting string variable this line.
答案 0 :(得分:0)
如果你的textview变量为null,那么这基本上意味着这个
TextView tv2 = (TextView) findViewById(R.id.source);
不会返回有效的TextView。
要理解它为什么不存在,我们需要包含TextView的xml。
此外,我还要感谢您尝试检索TextView的整个课程,因为您的class JavsScriptInterface
似乎没有扩展活动。
如果您需要任何进一步的帮助,请提供完整的代码和xml