Read More
Read now

Data Binding Part II – Image Binding

Save

Earlier we saw how to bind the text with layout in android, but what about image as generally all the image related android attributes deal with Bitmap of image while from server/ network we only get URI (or you can say URLs). So how go we map a imageview withe our image.

case-1: Transfer bitmap over network

But its the waste of users data and network channel as its way to much heavy and a single request can contain more than dozens of images. Moreover many of the images send by network is not even used. So its a bad idea!

case-2: Make a custom attribute and load the image in it.

And that will probably be the best way to bind your image as now you can bind them to the urls and also its really easy and you can do this without changing whatever library you were using earlier for the image loading. So I will show you two examples one with picasso and other with volley Image Loader.

First: Picasso

Create a class with any name, as i did ImageBinder.java now create your attribute in it

And just pass your URI/URL to the layout as

Second: Volley

The layout will be same just the method implementation will be changed

As you can see its quiet easy and can implement any method you want to add your images. So start binding your data in android.

Next>>

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


3 comments

  • Data Binding technique android Part-I - Mobikul
    […] Next Chapter […]
  • Data Binding Part-III: Recycler view - Mobikul
    […] As we are using app:imageUrl our custom setter so we have to define it. Here I am going to use picasso library if you want to use volley you can check it out from here. […]
  • Shubham Agarwal
    Really helpful specially BindingAdapter part. Thanks !!!
  • css.php

    Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

    Deniel Kerr

    Owner and Founder. Opencart

    Talk to Sales
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home