Pranav Mahajan Pranav Mahajan - 1 month ago 13
Android Question

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.


Here is the getView() method of the Adapter

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())
**** 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));


Answer Source

I found an answer from .

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 {
    viewHolder.profileImage_IV.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.no_image));