android - 带有自定义 ArrayAdapter 的 AutocompleteTextView

标签 android android-layout

我正在使用自定义 ArrayAdapter 在 AutocompleteTextView 上设置适配器(AddressAdapter 扩展 ArrayAdapter)。

因为我使用下拉列表来显示地址和到实际位置的距离,所以我必须用地址参数化数组适配器。

问题来了:方法

public Address getItem(int position)

给出地址列表的选定项。由于我使用 Address 作为 Adapter 基类,因此当我单击其中一项建议时,TextBox 将填充 Address 类的 toString() 表示。

如何更改此默认行为?

谢谢!

最佳答案

您可以覆盖 getView() 方法来更改每个项目的默认 View 。

您可以提取 TextView 并且由于 getView() 也将位置传递给您,您可以使用它来检索数据对象并操作显示的值.

关于android - 带有自定义 ArrayAdapter 的 AutocompleteTextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8771527/

相关文章:

android - CollapsingToolbarLayout 中的多行 TextView 而不是标题

android - Android Studio 布局编辑器中缺少属性

android - 控制 ListActivity 中的各个 View

android - 如何使用 WebView 显示地址栏?

android - 如何在后台生成我的缩略图?

android - Android 中的 values-sw 资源问题

android - 相对布局中的TextView水平中心

android - 在安卓上构建 vp8

java - 将 String[] 转换为 int[](或将 ArrayList<String> 转换为 ArrayList<Integer>)的优雅方式

Android appwidget 将其他小部件变成添加的小部件,而第二个小部件不起作用?