最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 高德地圖之poi搜索功能的實(shí)現(xiàn)代碼

 更新時(shí)間:2017年08月30日 11:54:23   作者:villa_mou  
這篇文章主要介紹了android 高德地圖之poi搜索功能的實(shí)現(xiàn)代碼,在實(shí)現(xiàn)此功能時(shí)遇到很多問題,在文章都給大家提到,需要的朋友可以參考下

廢話不多說,先看效果,如果大家感覺不錯(cuò),請(qǐng)參考實(shí)現(xiàn)代碼

這里寫圖片描述

這個(gè)功能我是用Fragmentdialog里面做的,也遇到不少坑

第一,就是設(shè)置背景的drawable為純白色導(dǎo)致鍵盤彈出的時(shí)候,recyclerview的布局被頂上去導(dǎo)致出現(xiàn)白色布局,有點(diǎn)扎眼;最后改成了設(shè)置為和背景色一個(gè)顏色就和好了

  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="請(qǐng)輸入關(guān)鍵字"
      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>

第二個(gè)問題是鍵盤彈出的時(shí)候,會(huì)出現(xiàn)dialog布局整體被頂上去

最后通過設(shè)置 style來解決

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

最后就是實(shí)現(xiàn)搜索功能了

第一個(gè)點(diǎn)擊搜索時(shí),鍵盤和搜索按鈕兩個(gè)都是同樣的效果

/**
   * 搜索功能
   */
  private void searchLocationPoi() {
    //關(guān)閉鍵盤
    KeyBoardUtils.closeKeybord(poiSearchInMaps, BaseApplication.mContext);
    if (TextUtils.isEmpty(poiSearchInMaps.getText().toString().trim())) {
      ToastUtils.showToastCenter("內(nèi)容為空!");
    } else {
      query = new PoiSearch.Query(poiSearchInMaps.getText().toString().trim(), "", "");// 第一個(gè)參數(shù)表示搜索字符串,第二個(gè)參數(shù)表示poi搜索類型,第三個(gè)參數(shù)表示poi搜索區(qū)域(空字符串代表全國)
      query.setPageSize(20);// 設(shè)置每頁最多返回多少條poiitem
      query.setPageNum(0);// 設(shè)置查第一頁
      poiSearch = new PoiSearch(getActivity(), query);
      poiSearch.setOnPoiSearchListener(this);
      poiSearch.searchPOIAsyn();
    }
  }

然后回調(diào)中進(jìn)行處理

@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);
    }
  }

    還有就是監(jiān)聽EditText里面內(nèi)容的變化來搜索,其實(shí)也很簡單

 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) {
      }
    });
  /**
   * 監(jiān)聽edittext內(nèi)容的變化,去搜索
   */
  private void textChangeSearch(CharSequence charSequence) {
    String content = charSequence.toString().trim();//獲取自動(dòng)提示輸入框的內(nèi)容
    Logger.e(content);
    InputtipsQuery inputtipsQuery = new InputtipsQuery(content, "");//初始化一個(gè)輸入提示搜索對(duì)象,并傳入?yún)?shù)
    Inputtips inputtips = new Inputtips(getActivity(), inputtipsQuery);//定義一個(gè)輸入提示對(duì)象,傳入當(dāng)前上下文和搜索對(duì)象
    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);
        }
      }
    });//設(shè)置輸入提示查詢的監(jiān)聽,實(shí)現(xiàn)輸入提示的監(jiān)聽方法onGetInputtips()
    inputtips.requestInputtipsAsyn();//輸入查詢提示的異步接口實(shí)現(xiàn)
  }

ok,搞定,最后只需要搞個(gè)回調(diào),把Search后點(diǎn)擊的item傳回去就好了.希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android Studio SVN使用方法教程

    Android Studio SVN使用方法教程

    這篇文章主要介紹了Android Studio SVN使用方法教程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Flutter中使用setState時(shí)的6個(gè)簡單技巧總結(jié)

    Flutter中使用setState時(shí)的6個(gè)簡單技巧總結(jié)

    平常在使用flutter的控件時(shí)我們都知道,要刷新頁面那么只需要調(diào)用setState()方法即可,這篇文章主要給大家介紹了關(guān)于Flutter中使用setState時(shí)的6個(gè)簡單技巧,需要的朋友可以參考下
    2022-05-05
  • Android使用Handler實(shí)現(xiàn)View彈性滑動(dòng)

    Android使用Handler實(shí)現(xiàn)View彈性滑動(dòng)

    這篇文章主要介紹了Android使用Handler實(shí)現(xiàn)View彈性滑動(dòng),介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-08-08
  • Android編程實(shí)現(xiàn)攝像頭臨摹效果的方法

    Android編程實(shí)現(xiàn)攝像頭臨摹效果的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)攝像頭臨摹效果的方法,涉及Android權(quán)限控制、布局及攝像頭功能調(diào)用等相關(guān)操作技巧,需要的朋友可以參考下
    2017-09-09
  • Android優(yōu)化應(yīng)用啟動(dòng)速度

    Android優(yōu)化應(yīng)用啟動(dòng)速度

    這篇文章主要介紹了Android優(yōu)化應(yīng)用啟動(dòng)速度,針對(duì)Android性能優(yōu)化中的加快應(yīng)用啟動(dòng)速度進(jìn)行學(xué)習(xí),感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android Fragment 基本了解(圖文介紹)

    Android Fragment 基本了解(圖文介紹)

    Android是在Android 3.0 (API level 11)開始引入Fragment的可以把Fragment想成Activity中的模塊,這個(gè)模塊有自己的布局,有自己的生命周期,單獨(dú)處理自己的輸入,在Activity運(yùn)行的時(shí)候可以加載或者移除Fragment模塊
    2013-01-01
  • Android 手機(jī)獲取手機(jī)號(hào)實(shí)現(xiàn)方法

    Android 手機(jī)獲取手機(jī)號(hào)實(shí)現(xiàn)方法

    本文主要介紹Android 獲取手機(jī)號(hào)的實(shí)現(xiàn)方法,這里提供了實(shí)現(xiàn)方法,和具體操作流程,并符實(shí)現(xiàn)代碼,有需要的小伙伴可以參考下
    2016-09-09
  • Android中PathMeasure仿支付寶支付動(dòng)畫

    Android中PathMeasure仿支付寶支付動(dòng)畫

    這篇文章主要為大家詳細(xì)介紹了Android中PathMeasure仿支付寶支付動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • 完美解決虛擬按鍵遮蓋底部視圖的問題

    完美解決虛擬按鍵遮蓋底部視圖的問題

    下面小編就為大家分享一篇完美解決虛擬按鍵遮蓋底部視圖的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Android?NDK開發(fā)之FFmpeg視頻添加水印

    Android?NDK開發(fā)之FFmpeg視頻添加水印

    這篇文章主要介紹了在Android?NDK開發(fā)中如何通過FFmpeg為視頻添加水印,文中的示例代碼講解詳細(xì),對(duì)我們了解Android開發(fā)有一定的幫助,感興趣的可以學(xué)習(xí)一下
    2021-12-12

最新評(píng)論

门头沟区| 天柱县| 汤阴县| 西青区| 都匀市| 岳阳县| 芜湖市| 曲沃县| 南安市| 雅安市| 博爱县| 望都县| 台江县| 凭祥市| 高平市| 永年县| 友谊县| 徐州市| 玉田县| 盘锦市| 新干县| 正定县| 革吉县| 武夷山市| 五大连池市| 连平县| 平利县| 深州市| 满洲里市| 新河县| 锡林浩特市| 皮山县| 吴堡县| 政和县| 深泽县| 西峡县| 康平县| 嘉禾县| 建阳市| 广安市| 河津市|