Android Developer

At Google I/O 2015 numerous new android developer libraries and tools were introduced. One of these was the brand new Data Binding library as well as in this series we’ll check out the library and explore a few of the effective features it offers.

In the last article we covered some fundamental Data Binding of text products to TextViews inside our layout there were some references which suggested that we’ll be also adding images. This can be a a bit more complex than simple text because we obtain a URL in the Twitter feed and this doesn’t associate straight to the Bitmap object we have to bind an ImageView to. Partly this will start to claim that the main difference between your Model and ViewModel within the MVVM pattern that the Data Binding library adopts.

Android Developer

Android Developer

Within this situation the Model consists of a URL however the View needs a Bitmap, and also the conversion in the Model towards the ViewModel ought to provide exactly what the View requires. That can be a is just true, and that’s the purpose the ViewModel is made for, within this situation there’s an alternate approach that people may use. The reasoning behind this really is that conversion from the Hyperlink to a Bitmap is really a non-trivial task needing a network transaction which can’t be efficiently carried out included in an easy object conversion pass. Also, the logic for doing android developer has already been encapsulated directly into third-party libraries that are mature and well examined, but might not be simple relating to towards the conversion itself.

Another issue we have here’s that since the network translation needed to acquire each Bitmap is costly, to get it done at the stage where we carry out the Model->ViewModel conversion indicates we all do it for those products within the List that’s passes towards the Adapter whether or not they’re really displayed or otherwise. This is greatly inefficient, and will be a massive waste from the users’ data, therefore we could be far better of deferring this until we all know that people need a Bitmap for display. So it’s a lot more efficient to construct this to the binding pass which only happens if we are really exhibiting a product inside the RecyclerView.