首页 > 解决方案 > 编辑文本更改时在编辑文本下方显示下拉列表

问题描述

我有一个用于输入位置的编辑文本,根据谷歌位置 API 的结果,我必须在编辑文本下方的下拉列表中显示它们。无法弄清楚如何在编辑文本下方创建一个下拉列表。附上图片供参考

示例图像

在此处输入图像描述

标签: androidandroid-layout

解决方案


实现您的设计的一种方法

在 XML 中

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">

        <EditText
            android:id="@+id/id_search"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/enter_building_or_street_address"/>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/id_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"/>
   </LinearLayout>

在班上

  • 实施TextWatcherEditText

  • onTextChanged -如果响应不为空,则调用 place api并列出响应
    recyclerview


推荐阅读