Android 中的自定义自动完成

发布于 2024-09-26 08:10:09 字数 312 浏览 0 评论 0原文

我想使用 AutoCompleteTextView 显示联系人姓名列表以及相应的电话号码

,例如



Vikas Patidar <9999999999>


当用户在手机中键入文本时, Rahul Patidar <9999999999>数字字段。

在默认样式中,我只能显示名称列表。

谁能告诉我如何实现这一点,以便当用户选择列表中的任何项目时,我可以在手机号码字段中显示该项目的号码。

I want to display List of Contact Names with the respective phone numbers

like


Vikas Patidar <9999999999>


Rahul Patidar <9999999999>


using AutoCompleteTextView when a user type text in the mobile number field.

In default style I can only display the list of names.

Can anyone please tell me how can I implement this so that when a user select any item in list and I can display number of that in Mobile number field.

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

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

发布评论

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

评论(1

羁〃客ぐ 2024-10-03 08:10:09

您需要使用适配器来完成此任务。例如,对于 SimpleAdapter

SimpleAdapter adapter = new SimpleAdapter(context, list, R.id.row_layout, new String[] { "Name", "Phone" }, new int[] { R.id.name, R.id.phone });
autoCompleteField.setAdapter(adapter);

为此,您需要创建一个布局 XML 文件并且列表必须是 List。第四个参数中的字符串是列表中地图的键。第5个参数中的整数是布局文件中组件的标识符。

或者您可以扩展任何适配器并使用它。请参阅此链接以供参考。

You need use adapter for this task. For example, with SimpleAdapter:

SimpleAdapter adapter = new SimpleAdapter(context, list, R.id.row_layout, new String[] { "Name", "Phone" }, new int[] { R.id.name, R.id.phone });
autoCompleteField.setAdapter(adapter);

For this you need make a layout XML file and list must be of type List<? extends Map<String, ?>. Strings in 4th parameter are keys for maps in list. Ints in 5th parameter are identifiers of components in layout file.

Or you can extend any adapter and use it. See this link for reference.

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