1

I am having an ImageView and a FrameLayout placed above it in the RecyclerView item. The FrameLayout's visibility is set to INVISIBLE by default. I am loading ImageView's image through a URL using Volley library. I want to show the Framelayout i.e. FrameLayout's visibility should be set to visible only when the image is loaded successfully and not before it. I have implemented listener to listen to the image loading which set the FrameLayout's visibility to visible once image is loaded. But the problem is as RecyclerView recycles view, I am getting some FrameLayout's visibility as VISIBLE even if the ImageView isn't loaded.

Here is my onBindViewHolder code:

@Override
public void onBindViewHolder(final ViewHolderBoxOffice holder, int position)
{
    holder.topContainer.setVisibility(View.INVISIBLE);
    holder.bottomContainer.setVisibility(View.INVISIBLE);

    String poster = "some image url";

    holder.mThumbnail.setImageUrl(poster, volleySingleton.getImageLoader());

    /* Listener for listening to image loading*/
    holder.mThumbnail.addOnLayoutChangeListener(new OnLayoutChangeListener()
    {
        @Override
        public void onLayoutChange(View view, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7,
                int arg8)
        {
            if(holder.mThumbnail.getDrawable()!=null)
            {
                holder.topContainer.setVisibility(View.VISIBLE);
                holder.bottomContainer.setVisibility(View.VISIBLE);
            }
            else
            {
                holder.topContainer.setVisibility(View.INVISIBLE);
                holder.bottomContainer.setVisibility(View.INVISIBLE);
            }
        }
    });
}
MrShadow
  • 171
  • 3
  • 16

0 Answers0