gpt4 book ai didi

java - butterknife ocClick 适配器 RecyclerView

转载 作者:行者123 更新时间:2023-12-01 19:33:02 27 4
gpt4 key购买 nike

从其中一个显示文本中,我将给出 clicklistener 函数。上面的编码是adpater列表中的编码。我使用 butterknife 存储库。我的 friend 们可以帮我制作点击监听器功能吗?

public class AllproductHolder extends RecyclerView.ViewHolder {

@BindView(R.id.txt_id)
TextView txt_id;
@BindView(R.id.txt_id_product_category)
TextView txt_id_product_category;
@BindView(R.id.txt_id_currency)
TextView txt_id_currency;
@BindView(R.id.txt_name_product)
TextView txt_name_product;
@BindView(R.id.txt_price_capital)
TextView txt_price_capital;
@BindView(R.id.txt_price_sale)
TextView txt_price_sale;
@BindView(R.id.txt_description)
TextView txt_description;
@BindView(R.id.txt_sku)
TextView txt_sku;
@BindView(R.id.txt_stock)
TextView txt_stock;
@BindView(R.id.txt_condition)
TextView txt_condition;
@BindView(R.id.txt_deliverable)
TextView txt_deliverable;
@BindView(R.id.txt_downloadable)
TextView txt_downloadable;
@BindView(R.id.txt_target_gender)
TextView txt_target_gender;
@BindView(R.id.txt_target_age)
TextView txt_target_age;
@BindView(R.id.txt_visibility)
TextView txt_visibility;
@BindView(R.id.image)
ImageView image;
@BindView(R.id.txt_image)
TextView txt_image;


public AllproductHolder(@NonNull View itemView) {
super(itemView);

ButterKnife.bind(this, itemView);
}

}

最佳答案

您只需将 @OnClick 注释添加到 ViewHolder 类即可。像这样的事情:

public class AllproductHolder extends RecyclerView.ViewHolder {

...

public AllproductHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);

}

@OnClick(R.id.image) // Change to your view id.
void onImageClicked() {
int position = getAdapterPosition();
// Do something for related item.
}

}

关于java - butterknife ocClick 适配器 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59243992/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com