Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowDuplicates(false) not working with SimpleCursorAdapter #39

Closed
jjalonso opened this issue Feb 27, 2014 · 3 comments
Closed

allowDuplicates(false) not working with SimpleCursorAdapter #39

jjalonso opened this issue Feb 27, 2014 · 3 comments
Labels

Comments

@jjalonso
Copy link

I think that i find a little bug.
allowDuplicates(false) appear dont work when is used with a SimpleCursorAdapter.

For reproduce it, this is my code.

Custom TokenCompleteTextView

public class ContactCompleteTextView extends TokenCompleteTextView {

    public ContactCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        allowDuplicates(false);
        setTokenClickStyle(TokenCompleteTextView.TokenClickStyle.Delete);
    }

    @Override
    protected View getViewForObject(Object object) {
        if (object != null) {
            Cursor c = (Cursor) object;

            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            LinearLayout view = (LinearLayout) inflater.inflate(R.layout.contact_token,
                    (ViewGroup) ContactCompleteTextView.this.getParent(), false);

            String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            ((TextView) view.findViewById(R.id.name)).setText(name);
            return view;
        }
        return null;
    }

    @Override
    protected Object defaultObject(String completionText) {
        // Avoid creation
        return null;
      }
  }

Initialization of adapter and view

        final String contactIdCol = ContactsContract.CommonDataKinds.Phone._ID;
        final String contactNameCol = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;
        final String contactPhoneCol = ContactsContract.CommonDataKinds.Phone.NUMBER;

        int[] displayViews = new int[] { android.R.id.text1, android.R.id.text2 };
        String[] displayCols = new String[] {
                contactNameCol,
                contactPhoneCol
        };

        final String[] queryProjection = new String[] {
                contactIdCol,
                contactNameCol,
                contactPhoneCol
        };

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_2, null, displayCols, displayViews, 0);

        adapter.setFilterQueryProvider(new FilterQueryProvider() {
            public Cursor runQuery(CharSequence constraint) {
                return getContentResolver().query(
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        queryProjection,
                        contactNameCol + " LIKE '%" + constraint + "%'",
                        null, null);
            }
        });

        mTtvContacts.setAdapter(adapter);
@mgod
Copy link
Contributor

mgod commented Mar 14, 2014

allowDuplicates(false) depends on the objects equals method. Can you check to see if two cursors that you think should be the same return true with equals?

@jjalonso
Copy link
Author

Is different because apply other filter query.

Juan Jose Alonso
http://jjalon.so
El 14/03/2014 01:41, "mgod" [email protected] escribió:

allowDuplicates(false) depends on the objects equals method. Can you
check to see if two cursors that you think should be the same return true
with equals?


Reply to this email directly or view it on GitHubhttps://github.com//issues/39#issuecomment-37604361
.

@mgod mgod added the bug label Jun 2, 2014
@mgod
Copy link
Contributor

mgod commented Mar 9, 2019

Version 3.0.0 now allows you to override the comparison for duplicates in shouldIgnoreToken

@mgod mgod closed this as completed Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants