java - 您如何为搜索引擎搜索设置布尔值与在 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 参考站点没有给我太多信息。如果可以的话请帮忙。这将不胜感激。提前致谢
解决方案
推荐阅读
- angular7 - 无法导航到左侧菜单或打开新报告?
- html - 我如何使底部图像居中?
- rust - 如何在 Rust 中反序列化(使用 serde)可选的 json 参数,可以是字符串或字符串数组
- hadoop - MapReduce 任务正在运行,但未生成 jhist 文件
- python - 如何一次检测一种颜色
- c++ - 从 .txt 文件中读取并将它们存储到带有类对象的向量中作为 C++ 中的值
- javascript - 使用 Javascript 过滤内容,但如何在内容位于多个“类别”中时
- c# - ASP.NET 核心 | gRPC “启动 gRPC 调用时出错:无法建立连接,因为目标机器主动拒绝了它。”
- c++ - 指令是否 printf(“%4.2f”, num); 显示四位数字,包括两位小数?
- javascript - 如何在 Class JS 中添加数组声明