广告
返回顶部
首页 > 资讯 > 精选 >Android中怎么实现poi搜索功能
  • 948
分享到

Android中怎么实现poi搜索功能

android 2023-05-30 21:05:04 948人浏览 独家记忆
摘要

Android中怎么实现poi搜索功能,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。第一,就是设置背景的drawable为纯白色导致键盘弹出的时候,recyclerview

Android中怎么实现poi搜索功能,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

第一,就是设置背景的drawable为纯白色导致键盘弹出的时候,recyclerview的布局被顶上去导致出现白色布局,有点扎眼;最后改成了设置为和背景色一个颜色就和好了

  Window window = getDialog().getWindow();    WindowManager.LayoutParams lp = window.getAttributes();    lp.gravity = Gravity.CENTER;    window.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.color_gray_f2)));    window.setAttributes(lp);

布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  xmlns:tools="http://schemas.android.com/tools"  android:background="@color/color_gray_f2"  android:orientation="vertical">  <RelativeLayout    android:id="@+id/search_maps_bar"    android:layout_width="match_parent"    android:layout_height="50dp"    android:layout_centerHorizontal="true"    android:layout_marginLeft="15dp"    android:layout_marginRight="15dp"    android:layout_marginTop="10dp"    android:background="@drawable/new_card">    <ImageButton      android:id="@+id/dialog_search_back"      android:layout_width="50dp"      android:layout_height="match_parent"      android:layout_centerVertical="true"      android:layout_margin="2dp"      android:background="@drawable/button_background_selector"      android:src="@drawable/ic_qu_appbar_back"/>    <ImageButton      android:id="@+id/dialog_serach_btn_search"      android:layout_width="50dp"      android:layout_height="match_parent"      android:layout_alignParentRight="true"      android:layout_centerVertical="true"      android:layout_margin="2dp"      android:background="@drawable/button_background_selector"      android:src="@drawable/ic_qu_search"      tools:ignore="ContentDescription,RtlHardcoded"/>    <EditText      android:id="@+id/dialog_search_et"      android:layout_width="wrap_content"      android:layout_height="match_parent"      android:layout_centerInParent="true"      android:layout_marginLeft="5.0dip"      android:layout_marginRight="5.0dip"      android:layout_toLeftOf="@+id/dialog_serach_btn_search"      android:layout_toRightOf="@+id/dialog_search_back"      android:background="@android:color/transparent"      android:completionThreshold="1"      android:dropDownVerticalOffset="1.0dip"      android:hint="请输入关键字"      android:imeOptions="actionSearch|flagNoExtractUi"      android:inputType="text|textAutoComplete"      android:maxHeight="50dp"      android:maxLength="20"      android:minHeight="50dp"      android:singleLine="true"      android:textColor="#000000"      android:textSize="16.0sp"/>  </RelativeLayout>  <android.support.v7.widget.RecyclerView    android:id="@+id/dialog_search_recyclerview"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:layout_marginLeft="15dp"    android:layout_marginRight="15dp"    android:layout_marginTop="@dimen/dp_10" /></LinearLayout>

第二个问题是键盘弹出的时候,会出现dialog布局整体被顶上去

最后通过设置 style来解决

  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    //解决dialogfragment布局不被顶上去的方法    setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar);  }

最后就是实现搜索功能了

第一个点击搜索时,键盘和搜索按钮两个都是同样的效果

  private void searchLocationPoi() {    //关闭键盘    KeyBoardUtils.closeKeybord(poiSearchInMaps, BaseApplication.mContext);    if (TextUtils.isEmpty(poiSearchInMaps.getText().toString().trim())) {      ToastUtils.showToastCenter("内容为空!");    } else {      query = new PoiSearch.Query(poiSearchInMaps.getText().toString().trim(), "", "");// 第一个参数表示搜索字符串,第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代表全国)      query.setPageSize(20);// 设置每页最多返回多少条poiitem      query.setPageNum(0);// 设置查第一页      poiSearch = new PoiSearch(getActivity(), query);      poiSearch.setOnPoiSearchListener(this);      poiSearch.searchPOIAsyn();    }  }

然后回调中进行处理

@Override  public void onPoiSearched(PoiResult poiResult, int errcode) {    Logger.e(poiResult.getPois().toString() + "" + errcode);    if (errcode == 1000) {      datas = new ArrayList<>();      ArrayList<PoiItem> pois = poiResult.getPois();      for (int i = 0; i < pois.size(); i++) {        LocationBean locationBean = new LocationBean();        locationBean.title = pois.get(i).getTitle();        locationBean.snippet = pois.get(i).getSnippet();        datas.add(locationBean);      }      searchCarAdapter.setNewData(datas);    }  }

    还有就是监听EditText里面内容的变化来搜索,其实也很简单

 poiSearchInMaps.addTextChangedListener(new TextWatcher() {      @Override      public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {      }      @Override      public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {        textChangeSearch(charSequence);      }      @Override      public void afterTextChanged(Editable editable) {      }    });    private void textChangeSearch(CharSequence charSequence) {    String content = charSequence.toString().trim();//获取自动提示输入框的内容    Logger.e(content);    InputtipsQuery inputtipsQuery = new InputtipsQuery(content, "");//初始化一个输入提示搜索对象,并传入参数    Inputtips inputtips = new Inputtips(getActivity(), inputtipsQuery);//定义一个输入提示对象,传入当前上下文和搜索对象    inputtips.setInputtipsListener(new Inputtips.InputtipsListener() {      @Override      public void onGetInputtips(List<Tip> list, int errcode) {        Logger.e(list.toString() + errcode);        if (errcode == 1000 && list != null) {          datas = new ArrayList<>();          for (int i = 0; i < list.size(); i++) {            LocationBean locationBean = new LocationBean();            Tip tip = list.get(i);            locationBean.latitude = tip.getPoint().getLatitude();            locationBean.longitude = tip.getPoint().getLongitude();            locationBean.snippet = tip.getName();            locationBean.title = tip.getDistrict();            datas.add(locationBean);          }          searchCarAdapter.setNewData(datas);        }      }    });//设置输入提示查询的监听,实现输入提示的监听方法onGetInputtips()    inputtips.requestInputtipsAsyn();//输入查询提示的异步接口实现  }

关于Android中怎么实现poi搜索功能问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注编程网精选频道了解更多相关知识。

--结束END--

本文标题: Android中怎么实现poi搜索功能

本文链接: https://www.lsjlt.com/news/221328.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android中怎么实现poi搜索功能
    Android中怎么实现poi搜索功能,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。第一,就是设置背景的drawable为纯白色导致键盘弹出的时候,recyclerview...
    99+
    2023-05-30
    android
  • android怎么实现搜索功能
    要实现Android应用的搜索功能,你可以按照以下步骤进行操作: 创建一个搜索框:在你的布局文件中添加一个EditText或Se...
    99+
    2023-10-26
    android
  • Android实现带列表的地图POI周边搜索功能
    先看效果图:(以公司附近的国贸为中心点) 上面是地图,下面是地理位置列表,有的只有地理位置列表(QQ动态的位置),这是个很常见的功能。它有个专门的叫法:POI周边搜索。 实现...
    99+
    2022-06-06
    列表 poi Android
  • Android中怎么实现淘宝搜索联想功能
    Android中怎么实现淘宝搜索联想功能,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。思考当搜索词为空时,不应该发起网络请求。在用户连续输入的情况下,可能会发起某些不必要的...
    99+
    2023-05-30
    android
  • java怎么实现搜索框搜索功能
    要实现搜索框搜索功能,可以按照以下步骤进行:1. 在前端页面上创建一个搜索框,如一个文本框和一个按钮。2. 在后端创建一个处理搜索请...
    99+
    2023-09-26
    java
  • Android实现模拟搜索功能
    本文实例为大家分享了Android实现模拟搜索功能的具体代码,供大家参考,具体内容如下 先看效果图,合适了再接着往下看: 我们看到的这个页面,是由两部分组成,顶部的自定义的搜索框,...
    99+
    2022-11-12
  • Android实现实时搜索框功能
    AutoCompleteTextView,自动完成文本框。用于实现允许用户输入一定字符后,显示一个下拉菜单,供用户从中选择,当用户选择某个选项后,按用户选择自动填写该文本框。该组件继承EditText,所以它支持EditText组件提供的属...
    99+
    2023-05-30
    android 搜索框 roi
  • Android怎么实现简单动态搜索功能
    本篇内容介绍了“Android怎么实现简单动态搜索功能”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!前言提到Android的动态搜索,大多应...
    99+
    2023-06-30
  • 自定义搜索功能Android实现
    先看看效果图: 源码下载:自定义搜索功能 代码: SearchActivity.java package com.bzu.gxs.search.activity; impo...
    99+
    2022-06-06
    自定义 Android
  • Android实现简单动态搜索功能
    目录前言一、addTextChangedListener二、本文案例1.介绍一下SearchView的一些方法2.准备数据3.初始化以及填充数据4.在SearchView中用户输入字...
    99+
    2022-11-13
  • Android实现高亮搜索功能的示例
    目录首先看效果图:使用方法:1、普通场景使用2、在DataBinding中使用首先看效果图: 整词高亮: 分词高亮: 下面贴上我封的方法 fun stringToHig...
    99+
    2022-11-12
  • Android ListView用EditText实现搜索功能效果
    前言 最近在开发一个IM项目的时候有一个需求就是,好友搜索功能。即在EditText中输入好友名字,ListView列表中动态展示刷选的好友列表。我把这个功能抽取出来了,先贴一...
    99+
    2022-06-06
    edittext listview Android
  • Android应用中怎么实现一个搜索记录保存功能
    今天就跟大家聊聊有关Android应用中怎么实现一个搜索记录保存功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。要点:就是缓存输入的内容到 本地 下面就是实现保存 搜索内容到本地 ...
    99+
    2023-05-31
    android roi
  • web用php怎么实现搜索功能
    PHP是一种广泛应用于Web开发中的服务器端脚本语言,它拥有强大的功能和灵活性,能够实现多种复杂的功能。其中,搜索功能无疑是用户最常用的功能之一,于是本文将介绍如何用PHP实现Web搜索功能。创建搜索表单在网站主页面上添加一个搜索表单,通常...
    99+
    2023-05-14
  • Android实现搜索功能并本地保存搜索历史记录
    本文实例为大家分享了Android实现搜索功能,并且需要显示搜索的历史记录,供大家参考,具体内容如下 效果图: 本案例实现起来很简单,所以可以直接拿来嵌入项目中使用,涉及到的...
    99+
    2022-06-06
    Android
  • SQL Server中怎么实现全文搜索功能
    这期内容当中小编将会给大家带来有关SQL Server中怎么实现全文搜索功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。一,创建全文目录和唯一索引创建全文索引之前,必须...
    99+
    2022-10-18
  • android实现搜索功能并将搜索结果保存到SQLite中(实例代码)
    运行结果: 涉及要点: ListView+EditText+ScrollView实现搜索效果显示 监听软键盘回车执行搜索 使用TextWatcher( )实时筛...
    99+
    2022-06-06
    SQLite Android
  • php怎么实现关键字搜索功能
    本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑php怎么实现关键字搜索功能?PHP实现关键字搜索后描红功能示例在刚开始学习php的时候,就对搜索过后的关键字描红感到好奇,但是这几天在巩固php基础的时候,就发现原来这...
    99+
    2018-09-10
    PHP 关键字 搜索 描红
  • 前端怎么实现搜索功能模块
    本篇内容介绍了“前端怎么实现搜索功能模块”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!用户使用产品,享受功...
    99+
    2022-10-19
  • 怎么用ajax实现简单搜索功能
    这篇文章主要讲解了“怎么用ajax实现简单搜索功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用ajax实现简单搜索功能”吧!本文实例讲述了基于aja...
    99+
    2022-10-19
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作