Android 고 덕 맵 의 poi 검색 기능 구현 코드
이 기능 은 저 는 Fragment dialog 에서 만 들 었 고 많은 구 덩이 를 만 났 습 니 다.
첫째,배경 을 설정 한 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 레이아웃 이 전체적으로 위로 올 라 가 는 것 입 니 다.마지막 으로 스타일 설정 으로 해결 할 게 요.
@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) {
}
});
/**
* edittext ,
*/
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();//
}
ok,해결,마지막 으로 리 셋 만 하고 검색 후 클릭 한 아 이 템 을 돌려 보 내 면 됩 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 님 께 서 바로 답 해 주 실 겁 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.