OK, trying to get images from my SD card to show in an activity ListView
.
I'm reading lots of hints, but I'm missing an important chunk. I'd love to see a short-ish bit of source code that illustrates this, haven't found anything yet.
From my research it sounds like bindview()
is called when listview.setadapter(SimpleCursorAdapter adapter)
is executed. The documentation says that setImageView
is called by bindview
if the ViewBinder
cannot handle an ImageView
.
You specify the field in the FROM
array, the id
of the TextView
in the TO
array, the Cursor
, and the view group with the TextView
. Then set the adapter to the ListView
and voila, it happens.
I think the call sequence is then:
listView.setAdapter(SimpleCursorAdapter adapter)->adapter.bindView()->adapter.setTextView
Bindview must determine the view is of type TextView, determine that it can bind it, passes the
TextViewand text value from the cursor and
setTextView` does its thing.
So, that makes the call for an ImageView
very similar, right?
listViw.setAdapter(SimpleCursorAdapter adapter)->adapter.bindView()->adapter.setImageView
So when bindView
comes across and object of type ImageView
, what does it do? Is there a default implementation like in setTextView
? I'd imagine it would be hard to do that, images vary so much. Text is text, but images have formats, sizes, depths, scale, LOCATIONS, etc, etc. The string passed to the setTextView
IS the text, the payload. In an image the string is (probably) the filename, only the starting point of an image.
I think I'll need to build my adapter with the database column name that holds the filename in FROM
. The TO
array will have just the id of the ImageView
in my layout. I think I can use the default viewbinder bindview(), but will have to override setImageView()
to take the expected string (filename), and build out the image loading lines to find that image name in the expected application path.
So that will be (maybe):
listView.setAdapter(MyOwnSimpleCursorAdapter myOwnAdapter)->myOwnAdapter.super.bindView()->myOwnAdapter.setImageView()
Does this sound right? If anyone can fill in the missing gaps and/or provide some working source code it would help a lot. By the way, I've written code to do this, but it isn't working. It could be a very simple bug and don't want to stop this thread if it's do-able. I think I just need a little nudge in the right direction.