6

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?

4

3 回答 3

4

我查看了 ButterKnife 的源代码,看起来 BKOnClickListener在您使用@OnClick(R.id.some_id)注释时会在视图上生成并设置 s。

现在,禁用的唯一方法OnClickListener是删除它:

item.setOnClickListener(null).

如果您再次需要它,您可以要求ButterKnife重复注射:

ButterKnife.inject(item);

那和 Ethan 提出的解决方案是我能想到的唯一解决方案。

于 2015-04-10T14:53:27.533 回答
2

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 }

于 2015-02-03T14:46:32.743 回答
1

您可以像在应用程序中一样添加一个布尔标志shouldListenClick,并在您希望的任何地方设置为 true 和 false。然后,您可以在执行其代码之前检查shouldListenClick@OnClick任何其他 ButterKnife 侦听器调用。

于 2017-03-31T09:30:18.663 回答