我正在为我的 ListView 实现 CustomAdapter 并使用 ViewHolder 类。我的代码是:
if (convertView == null) {
ViewHolder viewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.card_item, null);
viewHolder.ivCard = (ImageView) convertView
.findViewById(R.id.ivCardImage);
convertView.setTag(viewHolder);
}
final ViewHolder holder = (ViewHolder) convertView.getTag();
但是我的同事说我的变体可以错误地显示列表项并将其更正为
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.card_item, null);
holder.ivCard = (ImageView) convertView
.findViewById(R.id.ivCardImage);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
我知道他们的代码是最佳实践,但它真的会影响列表项映射吗?