MultiAutoCompleteTextView with Contact Phone Numbers

I need to create a MultiAutoCompleteTextView with contact phone numbers on a user device. What I need is like gmail; except gmail email addresses. For contacts, I have the following needs:

  • Each phone number must contain a record. So, if John has 3 numbers (home, cell, job), they are displayed as 3 entries

  • each entry is searchable by phone number or by personโ€™s name / surname

To create my adapter, I try to modify the one provided by Google , but when I download the sample, it does not compile (a view from the crappy experience, when a thing is right out of the box, but I'm trying to fix it). Then, using the sample at http://developer.android.com/reference/android/widget/MultiAutoCompleteTextView.html , I will bind my MultiAutoCompleteTextView adapter to the adapter. At the moment Iโ€™m not sure how to convert the adapter according to my needs (i.e., search for contacts by name or phone and get numbers). So my call for help is this: has anyone done this successfully and don't mind sharing their code? Or does anyone know how I can change the associated adapter to give me phone numbers that I can search by name or phone? And thirdly, will the adapter work with MultiAutoCompleteTextView?

Note

Asking this question, I made some assumptions about how Google implements their MultiAutoCompleteTextView for emails. Does anyone know if this code is open source? Does anyone know if my assumptions are correct? Will my idea work for implementing my MultiAutoCompleteTextView contact phone?

UPDATE

So, I have come a long way with the question. Now I use the AutoFill response with a name and number, as in the sms mobile app . But I am trying to convert the implementation to MultiAutoCompleteTextView, but this does not allow multiple entries to be used. Does anyone know how I can finish this?

UPDATE 2

Refer to Autocomplete with a name and number, as in the sms mobile app :

My MultiAutoCompleteTextView is currently working: it allows you to use multiple entries. I just replaced AutoCompleteTextView with MultiAutoCompleteTextView and I ignored another onItemClick answer. It works, sort of. Also, the data I receive is not the good formatted elements that you see in gmail EditText . So, back to the first question: how does Google do this? I donโ€™t want to waste time explaining how gmail compiles editText, as the appropriate reader can readily verify this. In their EditText I can enter four contacts, and then randomly click one at a time to delete it. I want to be able to do this. How?

+1
source share
1 answer

try the following:

 final Resources res = getResources(); LinearLayout ll = new LinearLayout(this); AutoCompleteTextView tv = new AutoCompleteTextView(this); tv.setThreshold(1); String[] from = { Phone.DISPLAY_NAME }; int[] to = { android.R.id.text1 }; SimpleCursorAdapter a = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null, from, to, 0); a.setStringConversionColumn(2); // Phone.NUMBER ViewBinder viewBinder = new ViewBinder() { @Override public boolean setViewValue(View v, Cursor c, int index) { TextView tv = (TextView) v; int typeInt = c.getInt(3); // Phone.TYPE CharSequence type = Phone.getTypeLabel(res, typeInt, null); // Phone.DISPLAY_NAME + Phone.NUMBER + type tv.setSingleLine(false); tv.setText(c.getString(1) + "\n" + c.getString(2) + " " + type); return true; } }; a.setViewBinder(viewBinder); FilterQueryProvider provider = new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { // run in the background thread Log.d(TAG, "runQuery constraint: " + constraint); if (constraint == null) { return null; } ContentResolver cr = getContentResolver(); Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, constraint.toString()); String[] proj = { BaseColumns._ID, Phone.DISPLAY_NAME, Phone.NUMBER, Phone.TYPE, }; return cr.query(uri, proj, null, null, null); } }; a.setFilterQueryProvider(provider); tv.setAdapter(a); ll.addView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); setContentView(ll); 
+2
source

All Articles