作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从其中一个显示文本中,我将给出 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/
从其中一个显示文本中,我将给出 clicklistener 函数。上面的编码是adpater列表中的编码。我使用 butterknife 存储库。我的 friend 们可以帮我制作点击监听器功能吗?
我是一名优秀的程序员,十分优秀!