For each entry in the list, an MvxItemTemplate is shown (which is referenced above as “@layout/item_entries”). This is the template which displays the entry’s title, thumbnail, etc.
In order to bind the Thumbnail control (which is an Android ImageView control) to the Thumbnail property of an EntryViewModel, it is necessary to create an MVVMCross Custom Binding, sub-classed from MvxAndroidTargetBinding.
Within this Custom Binding, the target type is set to “byte” (meaning “byte array”). However, like the Windows Image control, the Android ImageView control cannot bind to a byte array (however it can bind to an Android Bitmap). It would be possible to implement an Android Value Converter to do the conversion. However, this is unnecessary as the conversion can be done within the Custom Binding itself, in the SetValueImpl method.
The conversion is done asynchronously using a BitmapFactory, which has a method to convert a byte array to a Bitmap.
By using this approach, the Android project can now bind to the Entries property and asynchronously download and convert thumbnail data. This takes place on-demand i.e. there may be 100s of items in the ListView, but the thumbnail data is only loaded when the associated entry is scrolled into view.
As mentioned above, an Adapter will attempt to reuse Views (visible items) within the ListView. This, in conjunction with the asynchronous thumbnail loading, means that when scrolling through the list, a user may see a previously loaded image before the correct image is displayed.
(This may not be immediately apparent, but can be seen if a delay is deliberately added to the thumbnail loading code.)
To prevent this, the SetValueImpl method makes the Thumbnail ImageView control invisible until the thumbnail data has been downloaded and a Bitmap has been created and assigned to the control.