Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top