Recyclerview makes imageview disappear

Asked

Viewed 220 times

0

Simple. Recycler View makes imageView disappear after I scroll back to the top of the list. For example, in the case, the first image simply disappears.

It was like that: https://i.stack.Imgur.com/aEMFG.png After going to the bottom of the list and back, it was like this: https://i.stack.Imgur.com/Ioqaz.png

I am not using any library. The imageview from there is normal without any change. Including this photo is a background that I put in XML.

The texts don’t change, you can tell.

  • 1

    Friend, whenever you open a question, put the total or partial code that allows anyone who wants to help you to know what is really happening. His code could have several details that we can not see. Leonardo gave a great "kick" based on the effects, but without knowing the cause!

1 answer

3


You better put the code next to the question, to help with the solution.

But this "problem" is already known in Recyclerview.

You have an Adapter that creates your list, right?

Probably at the time you set the image, you are using an IF, right?

Whenever you go to work with Recyclerview+Adapter you must think about ELSE as well, because as the name says, it recycles the cells to create the rest of the list.

For example:

if(url.imgview != null){
    image.setImageURI(Uri.parse(url.imgview));             
} else {
    image.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_launcher));   
}

If the URL is empty or null, the icon of the application will be automatically placed, thus preventing already placed images from being repeated.

  • 2

    This is not a problem with Recyclerview, this is a problem with the wrong programming! Now, I think they gave you -1 in your reply because in her opening you made a comment that should have been added as a comment to the question itself!

  • 2

    @Loudenvier That’s why I put that probably he is doing this way, and I put an example, because he did not put the code of his problem, the war by reputation here is greater than the will to help someone, I’ve gotten used to

  • 1

    Thanks for the answer, but it wasn’t the right one. I made a mistake that cost me many, many hours. I’ve already solved what it was. I was taking the position on onBindViewHolder by the Holder.getAdapterPosition, and I should use the position only. The funny thing is that I’ve done a lot of Recycler view, and this one I don’t know why I missed. I was going crazy. I’ll be positive but I won’t take it for granted. Thanks

  • Leonardo, I’m glad you want to help. An answer only helps someone if you solve the problem posed. Answer questions that do not provide all the information, which require the answer to begin with "You better put the code next to the question, to help with the solution" and in between have "You have an Adapter that creates your list, right?", are "kick". What is intended here are quality answers that respond to the problem. Only then can they help someone.

  • "Reputation war"?, I don’t know what you mean. The answers get a negative vote when they are of no quality beyond the fact that those who vote see their reputation diminished.

  • 1

    I had another problem with IF/ELSE in RV. What a comedy. I’m going to give the answer as right now.

  • @Mr_anderson, do you want to explain why the answer is right? Your problem was the url.imgview be void or was the use of holder.getAdapterPosition()? I ask because I still can’t figure out what your problem was.

  • 1

    Looking here now, after I fixed the IF problem without ELSE the problem stopped; so I think the problem was only in IF/ELSE.

  • @Mr_anderson Good that solved, this "problem" of if/Else is known, so I put that example, but it is always good that when you have some problem, post your code together, hugs.

  • 1

    @ramaral the question was poorly asked, but as Leonardo has experience using Recyclerview he managed to correctly assume that the user who asked was making one of the most common mistakes in using Recyclerview. I think giving -1 in his answer was a very weird thing (I’m not saying it was you). It should be given -1 in the question! And commented on it to improve the quality. By the way, the quality of the questions in the Stack in Portuguese is painful, it seems that only people want to solve school/course duty here! And I’m using the comments as chat! :-(

  • @Loudenvier I also have experience in Recyclerview, hence knowing that the causes of that problem may be many. Leonardo was lucky to get it right. I, when I’m not sure, do not answer. Of course, Leonardo has every right to answer any questions he wants, and however he wants, he has no right to say that he is "reputation war" when an answer from him is negative. I gave -1 in the question and in the answer, I also voted to close the question as "unclear". Answering these kinds of questions is an incentive for bad questions.

  • 1

    @ramaral you didn’t even get to make a comment on the question asking for more information. I don’t think it was very lucky of Leonardo either, when I read the question, face to face, I imagined that it was this, and I was going to ask for more information, but I saw that there was already an answer and I left it there. Our postures are different in these cases, which is good, because, as the poet said, all unanimity is dumb. Hugging.

  • @Loudenvier What more information should I ask for? If a new user had requested the code, but that’s not the case.

  • 1

    @ramaral as I said, difference of postures.

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.