Android:AutoCompleteTextView 搜索不同的字段,然后在文本视图中插入内容

发布于 2024-09-11 07:14:53 字数 237 浏览 11 评论 0原文

有谁知道是否可以让 AutoCompleteTextView 的适配器搜索不同的字段,然后返回要插入的文本视图?

例如,我有一个包含电话号码、地址和姓名的字符串。这对于搜索很有用,因为我可以输入任何这些值来获取我想要的内容,但我只想将全名返回到要显示的 TextView?

这是否可能,或者适配器是否必须使用相同的值来搜索和返回 AutoCompleteTextView?

希望这是有道理的,感谢您的阅读, 托尼

Does anyone know if it's possible to have the adapter for an AutoCompleteTextView search a different field then what it returns to the text view to be inserted?

For example, I have a string that contains a phone number, an address, and a name. This works good for searching because I can enter any of those values to get what I want, but I only want the full name to be returned back to the TextView to be displayed?

Is this possible or does the adapter have to use the same value for both searching and returning to the AutoCompleteTextView?

Hope this makes sense, thanks for reading,
Tony

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我ぃ本無心為│何有愛 2024-09-18 07:14:53

对于它的价值:我认为另一个可能更干净的选项是设置 OnItemClickListener。在回调中,您可以在 AutoCompleteTextView 上调用 setText,传入您希望在视图中显示的任何字符串。

这为您提供了一个优势,即回调指示选择了哪个项目(例如,光标结果列表中的行)。否则,在我看来,您需要进行某种搜索才能找到与字符串关联的信息它被传递给 replaceText

For what it's worth: I think another, possibly cleaner, option would be to set an OnItemClickListener on the AutoCompleteTextView. In the callback, you can call setText on the AutoCompleteTextView, passing in whatever string you wish to appear in the view.

This gives you the advantage that the callback indicates which item was selected (e.g., the row in the cursor result list.) Otherwise, it seems to me that you need to do a search of some kind just to find the information associated with the string that gets passed in to replaceText.

数理化全能战士 2024-09-18 07:14:53

这比我想象的要简单得多。

您需要做的就是子类化 AutoCompleteTextView 或 MultiAutoCompleteTextView 并重写 ReplaceText 方法。

This was much simpler than I thought it would be.

All you need to do is subclass either AutoCompleteTextView or MultiAutoCompleteTextView and override the replaceText method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文