View view = View.inflate(context, R.layout.news_item_pager, null);
ButterKnife.bind(this, view);
View rollView = View.inflate(context, R.layout.layout_roll_view, null);
ButterKnife.bind(this,rollView);
这样写为什么报错 butterknife怎么绑定多个view?
View view = View.inflate(context, R.layout.news_item_pager, null);
ButterKnife.bind(this, view);
View rollView = View.inflate(context, R.layout.layout_roll_view, null);
ButterKnife.bind(this,rollView);
这样写为什么报错 butterknife怎么绑定多个view?
绑定多个View需要在注解里面写
写法如下:
@BindViews({R.id.view_1, R.id.view_2, R.id.view_3, R.id.view_4, R.id.view_5})
List<View> viewList;
8 回答6.4k 阅读
1 回答4.1k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
2 回答3.2k 阅读
2 回答3.9k 阅读
1 回答2.2k 阅读✓ 已解决
3 回答1.6k 阅读✓ 已解决
你是说调用
ButterKnife.bind()
时报错吗?首先要知道
ButterKnife.bind
的参数都是什么作用。第一个参数一般是定义需要绑定 View 的类。例如Activity
、Fragment
或者ViewHolder
即普通的类,只要是一个对象,类中有定义 @Bind 的注解都是可以工作的。第二个参数则是
ViewFinder
,也就是findViewById
方法的receiver
,它可以是Activity
或者View
。还有一种情况是
Activity
类中定义了@Bind
,这样Activity
对象就既是View
定义者又是ViewFinder
,所以只需要传入一个参数就可以了。我猜楼主的意思是一次性绑定多个
ViewFinder
的View
?这样的方法是不存在也不允许的,因为一个类中定义的@Bind
的 id 可能和其他 view 中定义的有重复,这种情况一般是定义多个 ViewHolder 来在一个类中使用。比如: