地图联系人照片与短信数据库android

时间:2014-07-05 04:22:38

标签: android listview sms simplecursoradapter

我正在尝试构建短信应用程序,我有基本的用户界面,显示联系人照片,姓名,短信时间和文本。这是代码: -

    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的游标中。所以图片显示正确,但在列表视图滚动图片开始显示在随机位置。如何使用SimpleCursorAdapter映射图片。 感谢

0 个答案:

没有答案