Search appears duplicated in AutoCompleteTextView

1

I'm having a problem using Android's AutoCompleteTextView .

AutoComplete is giving me duplicate data because I am searching both the name and the email. I would like it to present only one value, either by searching by the name of the contact or by searching for the email.

Basically, I have a list that stores a HashMap containing the name and email of each contact:

List<Map<String, String>> contact_list = new ArrayList<>();

To populate Hashmap , I use Cursor to help me fetch the information from the Database:

Cursor cursor = database.rawQuery(ContactTable.SELECT_ALL, null);

if(cursor.getCount() > 0){
     while(cursor.moveToNext()){
         Map<String, String> contact_info = new HashMap<>();
         contact_info.put("name", cursor.getString(ContactTable.COLUMN_CONTACT_NAME_IDX));
         contact_info.put("email", cursor.getString(ContactTable.COLUMN_CONTACT_EMAIL_IDX));
         contact_list.add(contact_info);
     }
}

After I add all instances of HashMap to my list, I add this list to a SimpleAdapter and then this adapter in my AutoCompleteTextView :

auto_adapter = new SimpleAdapter(
        mContext,
        contact_list,
        android.R.layout.simple_list_item_2,
        new String[]{"name", "email"},
        new int[]{android.R.id.text1, android.R.id.text2});
auto_complete.setAdapter(auto_adapter);

The threshold has value "1" and has been declared in the layout file:

<AutoCompleteTextView
    android:id="@+id/dialog_participant_name_auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:inputType="textCapWords"
    android:hint="@string/dialog_participant_auto_name"
    android:textColorHint="@color/hint_text_color"
    android:completionThreshold="1"
    android:visibility="gone"/>

It works almost perfectly, but it doubles the value of the search. For example, if I save a contact named "Fulano" and email "[email protected]" and search for "F", AutoCompleteTextView returns me two items:

    
asked by anonymous 21.08.2017 / 20:05

0 answers