I operate with recyclerview. I download all the contacts that I have on my phone (name and phone numbers). Everything looks fine, the problem is that when I spend the scroll in the view, when I return to the same contact, this contact does not have the correct phone numbers. The only thing that is changing. The name and contact phone number are displayed correctly.
For example, one contact just set up a mobile phone. It looks fine when initialized, but if I scroll and return, Home and Work are set with different numbers, and this user has set up only a mobile phone
Some help would be helpful!
This is my onBind method in recyclerAdapter:
@Override public void onBindViewHolder(ViewHolder holder, int position) { dataCursor.moveToPosition(position); holder.mTextView.setText((dataCursor.getString(1))); ContentResolver cr = context.getContentResolver(); String contactId = dataCursor.getString(dataCursor.getColumnIndex(ContactsContract.Contacts._ID)); Long photoTest = dataCursor.getLong(dataCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID)); if (dataCursor.moveToFirst()) { Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); if (phones == null) { phones.close(); } else { while (phones.moveToNext()) { try { Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{contactId}, null); while (pCur.moveToNext()) { int phoneType = pCur.getInt(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); String phoneNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); if(phoneType == TYPE_MOBILE){ holder.mNumberMoBilePhone.setText(phoneNumber); holder.mNumberMoBilePhone.setVisibility(View.VISIBLE); holder.textMobilePhone.setVisibility(View.VISIBLE); }else if(phoneType == TYPE_HOME){ holder.mNumberHomePhone.setText(phoneNumber); holder.mNumberHomePhone.setVisibility(View.VISIBLE); holder.textHomePhone.setVisibility(View.VISIBLE); }else if(phoneType == TYPE_WORK){ holder.mNumberWorkPhone.setText(phoneNumber); holder.mNumberWorkPhone.setVisibility(View.VISIBLE); holder.textWorkPhone.setVisibility(View.VISIBLE); }else{} } } catch (NullPointerException n) { } } phones.close(); } } if (photoTest != null) { ContactPhotoLoaderSdk5.instance().loadPhoto(holder.mContactPhoto, photoTest); } }
Not sure if there should be anything with this, but this is my choice:
String select = "((" + ContactsContract.Contacts.DISPLAY_NAME + " NOTNULL) AND (" + ContactsContract.Contacts.HAS_PHONE_NUMBER + " != 0 ))";
android android-recyclerview
SP Aug 16 '16 at 15:30 2016-08-16 15:30
source share