我想在懒惰的适配器上显示联系人照片。我设法将Photo_ID放入arrayList中我不知道如何在图像视图中显示它。
这就是我所做的:
while (cur.moveToNext())
{
String Sid = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String photo = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.PHOTO_ID));
Log.e("Photo",""+photo);
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", name);
map.put("id", Sid);
map.put("photo",photo);
DetailsList.add( map);
}
}
cur.close();
adapter = new ContactNamesAdapter(this, DataList);
// updating listview
cl.setAdapter(adapter);
}
}
记录照片的值时:我得到photo_ID#。我调用的适配器类显示如下名称:
public View getView(int position, View convertView, ViewGroup parent)
{
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.contacts_names_row, null);
TextView name = (TextView)vi.findViewById(R.id.name);
name.setText(data.get(position).get("name"));
return vi;
}
}
我坚持在适配器端显示照片ID?
答案 0 :(得分:0)
尝试获取PHOTO_URI
或PHOTO_THUMBNAIL_URI
而不是PHOTO_ID
。然后使用适配器将其显示在ImageView上。
答案 1 :(得分:0)
经过深入研究,我发现这将是显示图像的最简单方法。现在工作正常!
ImageView profile = (ImageView)vi.findViewById(R.id.imageHolder);
Uri my_contact_Uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id);
InputStream photo_stream = ContactsContract.Contacts.openContactPhotoInputStream(getContext().getContentResolver(),my_contact_Uri);
if(photo_stream != null)
{
BufferedInputStream buf =new BufferedInputStream(photo_stream);
Bitmap my_btmp = BitmapFactory.decodeStream(buf);
profile.setImageBitmap(my_btmp);
}
else
{
profile.setImageResource(R.drawable.no_pic);
}