Repository navigation
allowDuplicates(false) not working with SimpleCursorAdapter #39
Copy link
Copy link
Closed
Labels
Description
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);
Reactions are currently unavailable
Activity
mgod commentedon Mar 14, 2014
allowDuplicates(false)depends on the objectsequalsmethod. Can you check to see if two cursors that you think should be the same return true withequals?jjalonso commentedon Mar 14, 2014
Is different because apply other filter query.
Juan Jose Alonso
http://jjalon.so
El 14/03/2014 01:41, "mgod" notifications@github.com escribió:
mgod commentedon Mar 9, 2019
Version
3.0.0now allows you to override the comparison for duplicates inshouldIgnoreToken