splitwise / TokenAutoComplete

Gmail style MultiAutoCompleteTextView for Android
Apache License 2.0
1.3k stars 383 forks source link

Adding object programmatically, breaks allowDuplicates #148

Closed mstedler closed 9 years ago

mstedler commented 9 years ago

First, thanks for this great project.

I have this piece of code :

people = new Person[] {
                new Person("Marshall Weir", "marshall@example.com"),
                new Person("Margaret Smith", "margaret@example.com"),
                new Person("Max Jordan", "max@example.com"),
                new Person("Meg Peterson", "meg@example.com"),
                new Person("Amanda Johnson", "amanda@example.com"),
                new Person("Terry Anderson", "terry@example.com") };

        adapter = new ArrayAdapter<Person>(this,
                android.R.layout.simple_list_item_1, people);

        completionView = (ContactsCompletionView) findViewById(R.id.searchView);
        completionView.setAdapter(adapter);
        completionView.allowDuplicates(false);
        completionView.addObject(new Person("Marshall Weir", "marshall@example.com"));

it's possible to add "Marshall Weir" again manually, how can i workaround this?

Thanks in advance!

mgod commented 9 years ago

allowDuplicates depends on the equals method of the object. The Person objects I implemented use the object has value for comparisons, not the name or email, so if you want the new marshall to count as a duplicate, you need to override equals in the Person class.