I am trying to do something like this:

My problem is, and when I click on ImageViewmine, mine CardViewexpands, but n-th also expands CardView, which accepts the extended CardViewone that I clicked on. I do not understand why my method onClickalso applies to another CardView.
My adapter
public class CardsViewAdapter extends RecyclerView.Adapter<CardsViewAdapter.ViewHolder> {
private Game[] mDataset;
int rotationAngle = 0;
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTextView;
public ImageView imageView;
public LinearLayout test2;
public TextView test3;
boolean isPopupVisible;
public ViewHolder(View v) {
super(v);
mTextView = (TextView) v.findViewById(R.id.text_cards);
imageView = (ImageView) v.findViewById(R.id.item_description_game_more);
test2 = (LinearLayout) v.findViewById(R.id.popup_layout);
test3 = (TextView) v.findViewById(R.id.test_view);
isPopupVisible = false;
}
}
public CardsViewAdapter(Game[] myDataset) {
mDataset = myDataset;
}
@Override
public CardsViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.cards_resume_game, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final int pos = position;
holder.mTextView.setText(String.valueOf(mDataset[position].getId_game()));
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("POS","actual pos = "+pos);
holder.test3.setText("Position : "+pos);
if (holder.isPopupVisible) {
holder.isPopupVisible = false;
ObjectAnimator anim = ObjectAnimator.ofFloat(v, "rotation",rotationAngle, rotationAngle + 180);
anim.setDuration(500);
anim.start();
rotationAngle += 180;
rotationAngle = rotationAngle%360;
CardsAnimationHelper.collapse(holder.test2);
} else {
holder.isPopupVisible = true;
ObjectAnimator anim = ObjectAnimator.ofFloat(v, "rotation",rotationAngle, rotationAngle + 180);
anim.setDuration(500);
anim.start();
rotationAngle += 180;
rotationAngle = rotationAngle%360;
CardsAnimationHelper.expand(holder.test2);
}
}
});
}
@Override
public int getItemCount() {
return mDataset.length;
}
}
source
share