Android Developer


I’ve already pointed out third-party image loading libraries, so android developer formerly pointed out a compile reliance upon Glide. For individuals not really acquainted with Glide it offers a picture retrieval / conversion / loading pipeline that is invoked simply by chaining up procedures:

It instantly performs an asynchronous retrieval from the image after which sets it around the ImageView once complete. It may incorporate caching and all sorts of other nutrients, but we’ll only use it in the fundamental form here.

Android Developer

Android Developer

There’s really one serious problem with this particular. A fast check from the Data Binding expression language states:

A couple of procedures are missing in the expression syntax which you can use in Java.

Explicit generic invocation

We can’t make use of this inside an expression to consult the vista being certain to. However, stop worrying as there’s a mechanism build to the Data Binding library that people may use to beat this – custom setters. There might be instances, particularly when you’re using custom Sights, whenever android developer may decide to invoke a particular setter on the particular View, and custom setters provide this functionality. It’s also possible to utilize a custom setter to do an implicit conversion and that’s just what we want here because we want to use Glide to do the needed conversion from the Hyperlink to a Bitmap.

This can be a simple utility class which consists of just one method named setImageView() that takes an ImageView along with a String as arguments. When invoked it performs the Glide operation that people pointed out formerly. The main one important factor this is actually the @BindingAdapter(“imageUrl”) annotation that is telling the information Binding library this this can be a custom setter named “imageUrl”. We do not need to declare this in almost any config files or anything – the annotation itself is sufficient to make sure that this really is recognised at build time.