Custom AutoComplete in Android

≡放荡痞女 提交于 2019-12-13 02:47:15

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3891206/custom-autocomplete-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!