首页 > 解决方案 > 您如何为搜索引擎搜索设置布尔值与在 android studio 上的 webView 中输入的 URL

问题描述

所以我是 Android 开发的新手。我正在编写一个浏览器应用程序来练习。目标是让用户能够输入 URL,然后网站会在搜索/浏览器栏中拉出或仅用于 google 搜索的关键字。我遇到的问题是,它只是执行谷歌搜索,但无法识别是否输入了 URL。我没有错误。调试让我觉得应用程序很好并且可以工作,并且没有停止应用程序的错误。我对问题可能是什么感到茫然。下面是代码

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);


                if (editText.getText().toString() == "whateverText") {
                    // this line is looking for a keyword or URL
                }

                webView.loadUrl("https://" + editText.getText().toString());
                webView.loadUrl("https://www.google.com/#q=" + editText.getText());
                /* these 2 lines are needed to identify if its a URL search or Keyword search */


            }


        });

我以前用布尔值编码过,我只是迷失在浏览器中的位置和实现方式。据我了解,不能使用公共无效设置布尔值,并且 android studio 参考站点没有给我太多信息。如果可以的话请帮忙。这将不胜感激。提前致谢

标签: javaandroidif-statementonclickboolean

解决方案


推荐阅读