




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android中怎么实现poi搜索功能
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="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="/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)
{
}
});
/**
*
监听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
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- (二模)2025年深圳市高三年级第二次调研考试地理试卷(含标准答案)
- 专业介绍课件
- 高速公路改建工程承包合同书
- 辽宁政法职业学院《生物工程导论》2023-2024学年第二学期期末试卷
- 洛阳科技职业学院《西方医学史》2023-2024学年第二学期期末试卷
- 江苏省两校2024-2025学年高三四模(5月)物理试题试卷含解析
- 云南省昭通市昭阳区达标名校2024-2025学年初三年级第一次调研考试生物试题含解析
- 苏州工业园区职业技术学院《中国大学发展史》2023-2024学年第二学期期末试卷
- 苏州幼儿师范高等专科学校《大学化学及实验》2023-2024学年第二学期期末试卷
- 吉林省白城市通榆一中2024-2025学年高三期末热身联考英语试题含解析
- 健康教育心肺复苏知识讲座(3篇模板)
- 五年级上册体育教案(表格式)
- DL-T5190.1-2022电力建设施工技术规范第1部分:土建结构工程
- (正式版)JTT 1499-2024 公路水运工程临时用电技术规程
- 中国高清荧光腹腔镜行业市场现状分析及竞争格局与投资发展研究报告2024-2034版
- 国企管理人员招聘考试题库
- 托管老师员工手册
- 中医养生的健康体重
- 中石化公司招聘考试真题
- 统编版一年级语文下册部编版第六单元单元教材解读(素材)(课件)
- 乳腺结节手术后的护理
评论
0/150
提交评论