Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript将Android字符串转换为WebView_Javascript_Android_Webview_Android Webview - Fatal编程技术网

使用Javascript将Android字符串转换为WebView

使用Javascript将Android字符串转换为WebView,javascript,android,webview,android-webview,Javascript,Android,Webview,Android Webview,我正在尝试将意图数据获取到加载的WebView。 在意图之前,有一个EditText,我最初使用这些值登录到myURL站点,并在该活动中使用WebView,其中有userID和userPW(在站点上)。 但是为了更好的设计,我已经将Webview移动到另一个活动,并发送ID,PW和Bundle。 问题是字符串变量email和password似乎设置得很好,但是当我尝试使用我以前使用的相同代码时,它不起作用。 Android中是否有一些规则,没有用户输入,我不能直接传递变量?有人知道如何解决这个

我正在尝试将意图数据获取到加载的WebView。
在意图之前,有一个EditText,我最初使用这些值登录到myURL站点,并在该活动中使用WebView,其中有userID和userPW(在站点上)。

但是为了更好的设计,我已经将Webview移动到另一个活动,并发送ID,PW和Bundle。
问题是字符串变量email和password似乎设置得很好,但是当我尝试使用我以前使用的相同代码时,它不起作用。

Android中是否有一些规则,没有用户输入,我不能直接传递变量?
有人知道如何解决这个问题吗?


下面是我目前一直使用的代码

public class MyWeb extends Activity{
WebView webview;
String email;
String password;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(activity_myweb);

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    email = bundle.getString("ID");
    password = bundle.getString("PW");

    webview = (WebView)findViewById(R.id.logIn);
    webview.setWebViewClient(new WebClient());
    webview.getSettings().setDatabaseEnabled(true);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("myURL");

    login(email, password);



}


private void login(String id, String pw){
    webview.loadUrl("javascript: {" +
            "document.getElementById('userID').value = '"+email +"';" +
            "document.getElementById('userPW').value = '"+password+"';" +
            "var a = document.getElementsByTagName('input');" +
            "a[2].CheckSubmit(); };");
    webview.loadUrl("javascript:CheckSubmit()");
}
解决了,我想这是因为在网页加载之前调用了JS,认为在此之前的活动在我输入字段时加载了所有页面

     webview.setWebViewClient(new WebClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            webview.loadUrl("javascript: {" +
                    "document.getElementById('userID').value = '" + email + "';" +
                    "document.getElementById('userPW').value = '" + password + "';" +
                    "var a = document.getElementsByTagName('input');" +
                    "a[2].CheckSubmit(); };");
            webview.loadUrl("javascript:CheckSubmit()");
        }
    });