Android: ListAdapter populating image (icon) source
I'm populating a list from the DB, and i have a image field in the DB which contains a URL to a image file.
ListAdapter adapter=new SimpleCursorAdapter(this,
R.layout.row, constantsCursor,
new String[] {"title", "subtitle", "image"},
new int[] {R.id.value, R.id.title, R.id.icon});
However, the other fields are populated, but the image r开发者_开发技巧emains empty. Why?
- most likely you get an exception, and it woulf have been best if you showed that exceptions here.
- From my experience with android and SQLight + images you don't get the image but a URL that points to the image and then you need to retrieve the image itself by using
getContentResolver().openInputStream()
this is how,for example, you retrieve contact's images, you query the contact's details for the image uri and then open the input stream the way i showed you. to do it using the simple cursor adapter, if that's the case here, you also need to implement ViewBinder so when the cursor adapter sees the uri it will know to retrieve the data and put it in the view.
精彩评论