(注:本教程仅针对Butterknife 8.x)
在adapter中使用方法如下:
getView中
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_fun, null);
viewHolder = new ViewHolder(convertView);//这句变化
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Viewholder中
static class ViewHolder {
@BindView(R.id.iv_pic) ImageView ivPic;
@BindView(R.id.item_name) TextView itemName;
ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
其余和以往一样处理。