为什么在 ViewHolder 模式中,ViewHolder 类应该是静态的?
2022-09-01 23:50:15
我只是试图更好地理解我经常用来优化的以下模式ListView
我的阅读只向我指出了一个事实,即静态内部类被视为顶级类。与成员类(非静态)相比,这种东西有什么好处?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Comment comment = getItem(position);
ViewHolder holder;
if (convertView == null){
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.mylayout, null);
holder.nickname = (TextView) ((ViewGroup) convertView).findViewById(R.id.nickname);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.nickname.setText(comment.getMember_nickname());
CharSequence
return convertView;
}
public static class ViewHolder{
TextView nickname;
}