I recently witnessed a weird behaviour, when I used ButterKnife to bind an OnClick method of an image button inside an Adapter, as pointed in the title of this question. As suggested in the documentation I declared an inner class ViewHolder, where all the @Bind
declarations happen, I also have @OnClick
.
My ViewHolder class looks like this:
class ViewHolder {
private Product product;
@Bind(R.id.title)
TextView text;
@Bind(R.id.price)
TextView price;
public ViewHolder(View view, Product product) {
ButterKnife.bind(this, view);
this.product = product;
}
@OnClick(R.id.image_button)
public void launchProductFragment() {
ProductFragment fragment = new ProductFragment();
Bundle args = new Bundle();
args.putInt(Tools.WS_PRODUCT_GROUP_ID, product.getId());
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
}
}
Note: When I set a good old OnClickListener directly in my getView
method, the click works properly, and displays the expected result.
Is this a known issue? Or something I did in my implementation causes it?