How can I match elements one-to-one?

3448 views java
-3

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;

@Override
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() {

    @Override
    public void onClick(View v) {
       if (isUp) {
           slideDown(myViewHolder.infoView);
       } else {
           slideUp(myViewHolder.infoView);
       }
           isUp = !isUp;
       }
    });

return myViewHolder;
}

public MyViewHolder(View itemView) {
   super(itemView);
   init();
}

void init() {
   imageView = itemView.findViewById(R.id.imageViewID);
   ...

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

answered question
Add a Comment

1 Answer

8
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.