自定义自动完成在Android中 [英] Custom AutoComplete in Android

查看:100
本文介绍了自定义自动完成在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要与各自的电话号码,以显示联系人的名称列表

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

维卡斯Patidar< 9999999999>

拉胡尔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.

推荐答案

您需使用适配器完成这个任务。例如,对于<一href=\"http://developer.android.com/reference/android/widget/SimpleAdapter.html\">SimpleAdapter:

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);

为此,你需要做一个布局的XML文件和列表的类型必须为名单,LT ;?扩展地图&LT;弦乐,&GT; 。在第四个参数字符串是在列表地图键。在第五个参数int为组件标识符布局文件。

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.

这篇关于自定义自动完成在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆