확장 SimpleCursorAdapter를 사용하여 연락처를 목록에로드했는데 이제 연락처 사진을로드하려고합니다. 코드를 실행할 때 임의의 연락처 사진은 사진이없는 사람들을 위해 임의의 연락처 옆에 나타납니다. 왜 그 사진을 가지고 사진 옆에있는 사람들에게 사진을 보내지 않는 것일까 요? 당신이해야하지연락처 목록에 연락처 사진로드 : 임의 연락처 사진이 잘못된 위치에 나타납니다.
ImageView photo = (ImageView) findViewById(R.id.photo);
: loadContactPhoto에
public void bindView(View view, Context context, Cursor cursor) {
ImageView photo = (ImageView) findViewById(R.id.photo);
long photoId = cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID));
Bitmap photoBitmap = loadContactPhoto(photoId);
if (photoBitmap != null) {
photo.setImageBitmap(photoBitmap);
}
그리고 코드 :
의 Bindview()에서public Bitmap loadContactPhoto(long id) {
Uri contactUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, id);
byte[] data = null;
Cursor cursor = managedQuery(
contactUri, // Uri
new String[] { ContactsContract.CommonDataKinds.Photo.PHOTO }, // projection, the contact photo
ContactsContract.Contacts.PHOTO_ID + "!= 0", // where statement, only if the contact has a photo
null, null);
Log.i(LOG_TAG, "cursorCount: " + cursor.getCount()); // returns 1
if (cursor == null || !cursor.moveToNext()) {
return null;
}
data = cursor.getBlob(0);
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
return bitmap;
}
"보기보기"를 어떻게 구현 했습니까? – SpicyWeenie