#android #listview #sms #simplecursoradapter
#Android #listview #sms #simplecursoradapter
Вопрос:
Я пытаюсь создать приложение sms, и у меня есть базовый пользовательский интерфейс, который показывает фотографию контакта, имя, время sms и текст. вот код :-
lv = (ListView) v.findViewById(R.id.listview);
final Uri inboxURI = Uri.parse("content://mms-sms/conversations/");
final String[] projection = new String[] { "*" };
cr = v.getContext().getContentResolver();
Cursor cursor = cr.query(inboxURI, projection, null, null,
Telephony.Sms.Inbox.DEFAULT_SORT_ORDER);
madapter = new ContactsViewAdapter(v.getContext(), R.layout.list_row,
cursor, new String[] { "body", "address", "date", "thread_id" },
new int[] { R.id.text_msg, R.id.phone_number, R.id.time_date,
R.id.thread_id_map }); //SimpleCursorAdapter
lv.setAdapter(madapter);
код для запроса фотографии контакта :-
public Uri getPhotoUri(Context ct, long contactId) {
ContentResolver contentResolver = ct.getContentResolver();
try {
Cursor cursor = contentResolver
.query(ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.CONTACT_ID
"="
contactId
" AND "
ContactsContract.Data.MIMETYPE
"='"
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
"'", null, null);
if (cursor != null) {
if (!cursor.moveToFirst()) {
return null; // no photo
}
} else {
return null; // error in cursor process
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
Uri person = ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, contactId);
return Uri.withAppendedPath(person,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
}
но проблема в том, что фотографии контактов не отображаются в listview, поскольку их нет в курсоре SimpleCursorAdapter. Итак, фотографии отображаются правильно, но при прокрутке listview фотографии начинают отображаться в случайном положении. Как я могу сопоставить фотографии с помощью SimpleCursorAdapter.
Спасибо