How can I match elements one-to-one?

3448 views java

I have a Recyclerview and there are Imageviews in it. When I click any of image, I want to make visible a number of information about image on the image.

Well, I did it but it seems everything's happening randomly... When I click first image, informations appearing on the second, when I click on the second its working normally and when I click third, nothing happening etc.

Here is some of my code;

public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item, parent, false);

    myViewHolder = new MyViewHolder(view);

    myViewHolder.imageView.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
       if (isUp) {
       } else {
           isUp = !isUp;

return myViewHolder;

public MyViewHolder(View itemView) {

void init() {
   imageView = itemView.findViewById(;

It seems I should group some elements or is there any better idea, way ?

answered question
Add a Comment

1 Answer

S-Sh 0 Comments

You should add listener for the ViewHolder in onBindViewHolder, and not onCreateViewHolder

posted this

Please login first before posting an answer.