Search code examples
androidfirebaseandroid-glidefirebaseui

Loading Images with Glide and FirebaseUI not working with BaseAdapter


I'm trying to load ProfileImages in a ListView (I know its outdated) by extending BaseAdapter using the Glide method provided in 'com.firebaseui:firebase-ui-storage:0.6.0' package.

Reference: https://firebase.google.com/docs/storage/android/download-files#downloading_images_with_firebaseui

Here is the getView() method of the Adapter

@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
...
if (tempProfile != null) {
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("path_to_image");

    **** Problem ****
    Glide.with(context /* context */)
            .using(new FirebaseImageLoader())
            .load(storageRef)
            .into(viewHolder.profileImage_IV);
    **** See alternate line of code ****
}
else {
  viewHolder.profileImage_IV.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.no_image));
}

****PROBLEM****: The glide line of code inflates images in ImageView of ALL THE ROWS(a lot of unnecessary rows get iflated by the image). The else{} part is able to overwrite a few images but not all the images. And therefore, I get INCORRECT result.

OBSERVATION: But instead of Glide line of code, if I use this line then I get the CORRECT result.

viewHolder.profileImage_IV.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.accept));

Thanks!


Solution

  • I found an answer from https://stackoverflow.com/a/35114351/2937847 .

    Basically if you inflate an ImageView using Glide, then you must clear it also using Glide. I had to add just 1 line in else{}

    else {
        Glide.clear(profileImage_IV);
        viewHolder.profileImage_IV.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.no_image));
    }