I set @OnClick listener to a view in a list item. In some cases I need to disable the listener for this view so that the list view can handle the click (OnItemClickListener should be called), and then enable it again. Is there a way to do this with Butterknife?
I've looked through the ButterKnife sources and it looks like BK generates and sets OnClickListeners on views when you're using @OnClick(R.id.some_id) annotation.
Now, the only way to disable OnClickListener is to remove it:
item.setOnClickListener(null).
If you need it again, you can ask ButterKnife to repeat the injection:
ButterKnife.inject(item);
That and the solution proposed by Ethan are the only solutions I can think of.
With Butterknife I don't know. But I know you can do this by creating a private boolean and an if statement. if(yourboolean == true){ //set your onClickListener }else{//do nothing }
You can add a boolean flag like shouldListenClick in the app and set to true and false where ever you wish. Then, you can check the shouldListenClick in the @OnClick or any other ButterKnife listener call before executing its code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With