recyclerview нажмите, перейдите на новую страницу android page info.xml и отправьте название продукта. Я пытаюсь создать приложение для электронной коммерции. Как добавить onclick в список RecyclerView, открыть страницу с информацией о продукте, например, новую активность, я также хотел бы отправитьНазвание и идентификатор продукта на странице информации о продукте,
public class adepter extends RecyclerView.Adapter<adepter.viewholder> {
private Context mCtx;
private List<Product> productList;
public adepter(Context mCtx, List<Product> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
@NonNull
@Override
public viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater=LayoutInflater.from(mCtx);
View v =inflater.inflate(R.layout.product_list, parent, false);
return new viewholder(v);
}
@Override
public void onBindViewHolder(@NonNull viewholder holder, int position) {
Product product = productList.get(position);
//loading the image
Glide.with(mCtx)
.load(product.getImage())
.into(holder.imageView);
holder.textViewTitle.setText(product.getTitle());
holder.textViewShortDesc.setText(product.getShortdesc());
holder.textViewtype.setText(String.valueOf(product.getType()));
holder.textViewPrice.setText(String.valueOf(product.getPrice()));
}
@Override
public int getItemCount() {
return productList.size();
}
public class viewholder extends RecyclerView.ViewHolder{
TextView textViewTitle, textViewShortDesc, textViewtype, textViewPrice;
ImageView imageView;
public viewholder(@NonNull View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.textViewTitle);
textViewShortDesc = itemView.findViewById(R.id.textViewShortDesc);
textViewtype = itemView.findViewById(R.id.textViewRating);
textViewPrice = itemView.findViewById(R.id.textViewPrice);
imageView = itemView.findViewById(R.id.imageView);
}
}
}