Monday, 26 August 2013

MultiAutoCompleteText contacts

MultiAutoCompleteText contacts

I want to do a MultiAutoCompleteTextView like this:

I can retrieve contacts numbers in an array and names in an array. How can
I do this MultiAutoCompleteTextView? For example, in the picture if you
enter ca there is a suggestion and if you enter 22, there is same
suggestion, and they are under the other. I have two arrays numbers[] and
names[], a MultiAutoCompleteTextView.
Here is my code:
Cursor phones =
getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,null,null, null);
ArrayList<String> numbers = new ArrayList<String>();
ArrayList<String> names = new ArrayList<String>();
while (phones.moveToNext())
{
names.add(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
numbers.add(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
}
phones.close();
String[] numbersArray = new String[numbers.size()];
String[] namesArray = new String[names.size()];
numbers.toArray(numbersArray);
names.toArray(namesArray);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, namesArray);
MultiAutoCompleteTextView textView =
(MultiAutoCompleteTextView)findViewById(R.id.edt_numara);
textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
textView.setAdapter(adapter);
But it works only for names and numbers isn't showing.

No comments:

Post a Comment