其他分享
首页 > 其他分享> > 山东大学项目实训-地图圈系统-APP(6)

山东大学项目实训-地图圈系统-APP(6)

作者:互联网

安卓开发高德地图–搜索关键字提示以及提示内容的显示

关键字的提示

使用

1.构造 InputtipsQuery 对象

2.构造 Inputtips 对象

3.调用 PoiSearch 的 requestInputtipsAsyn() 方法发送请求。

4.InputtipsListener的onGetInputtips()方法获得结果

InputtipsQuery inputquery = new InputtipsQuery(newText, "");
Inputtips inputTips = new Inputtips(self, inputquery);
inputquery.setCityLimit(true);
inputTips.setInputtipsListener(inputtipsListener);
inputTips.requestInputtipsAsyn();
提示内容的显示

使用自定义listView来显示

布局代码:

<ListView
    android:id="@+id/id_gaode_location_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:overScrollMode="never"
    android:scrollbars="none"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/color_while"
                android:gravity="center_vertical"
                android:orientation="vertical"
                android:padding="15dp">

    <ImageView
        android:id="@+id/id_gaode_location_search_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:background="@drawable/img_gaode_location_search_icon"
        android:scaleType="fitXY"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        android:layout_toEndOf="@+id/id_gaode_location_search_icon"
        android:layout_toStartOf="@+id/id_gaode_location_search_confirm_icon"
        android:orientation="vertical"
        android:layout_toLeftOf="@+id/id_gaode_location_search_confirm_icon"
        android:layout_toRightOf="@+id/id_gaode_location_search_icon">

        <TextView
            android:id="@+id/id_gaode_location_search_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:textColor="#000000"
            android:text=""
            android:textSize="16sp"/>

        <TextView
            android:id="@+id/id_gaode_location_search_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textColor="@color/color_c9"
            android:textSize="13sp"/>

    </LinearLayout>

    <ImageView
        android:id="@+id/id_gaode_location_search_confirm_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/icon_gaode_location_confirm_icon"
        android:scaleType="fitXY"/>

</RelativeLayout>

自定义的listView

public class GaoDeSearch_Adapter extends BaseAdapter {

    private List<Search_details> data;
    private Context context;

    private int selectedPosition = 0;

    public GaoDeSearch_Adapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    public void setData(List<Search_details> data) {
        this.data = data;
    }

    public void clearData() {
        this.data = null;
    }

    public void setSelectedPosition(int selectedPosition) {
        this.selectedPosition = selectedPosition;
    }

    public int getSelectedPosition() {
        return selectedPosition;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_gaode_location_search_info, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.bindView(position);
        return convertView;
    }

    class ViewHolder {
        TextView textTitle;
        TextView textSubTitle;
        ImageView imageCheck;

        public ViewHolder(View view) {
            textTitle = (TextView) view.findViewById(R.id.id_gaode_location_search_title);
            textSubTitle = (TextView) view.findViewById(R.id.id_gaode_location_search_content);
            imageCheck = (ImageView) view.findViewById(R.id.id_gaode_location_search_confirm_icon);
        }

        public void bindView(int position) {
            if (position >= data.size())
                return;
            Search_details poiItem = data.get(position);
            textTitle.setText(poiItem.getName());
            textSubTitle.setText(poiItem.getAddress());
            imageCheck.setVisibility(View.INVISIBLE);

            textSubTitle.setVisibility((position == 0 && poiItem.getPoiID().equals("regeo")) ? View.GONE : View.VISIBLE);
        }
    }
}

在activity中将数据加入到listView中

listView = (ListView) findViewById(R.id.id_gaode_location_list);
searchResultAdapter = new GaoDeSearch_Adapter(self);
listView.setAdapter(searchResultAdapter);
        resultData.clear();
        resultData.addAll(poiItems);
        searchResultAdapter.setData(resultData);
        searchResultAdapter.notifyDataSetChanged();

注意:searchResultAdapter.notifyDataSetChanged();更新数据后要加上这句话

效果图:
在这里插入图片描述
在这里插入图片描述

标签:int,山东大学,APP,id,实训,position,data,public,convertView
来源: https://blog.csdn.net/weixin_43677710/article/details/115840762