优化ListView提升运行效率

来源:互联网 发布:业主信息采集软件 编辑:程序博客网 时间:2024/04/29 03:27

优化

这里写图片描述
这里写图片描述

public View getView(int position, View convertView, ViewGroup parent) {        //LauoutInflater        ViewHolder vh = null;        Student student = mData.get(position);        if (convertView == null) {            vh=new ViewHolder();            convertView = mInflater.inflate(R.layout.list_simple_item, null);            vh.name = (TextView) convertView.findViewById(R.id.name);            vh.age = (TextView) convertView.findViewById(R.id.age);            vh.sex = (TextView) convertView.findViewById(R.id.sex);            vh.hobby = (TextView) convertView.findViewById(R.id.hobby);            vh.img = (ImageView) convertView.findViewById(R.id.img);            convertView.setTag(vh);        } else {            vh = (ViewHolder) convertView.getTag();        }        vh.name.setText(student.getName());        vh.age.setText(student.getAge());        vh.sex.setText(student.getSex());        vh.hobby.setText(student.getHobby());        vh.img.setImageResource(student.getImg());        return convertView;    }    class ViewHolder {        TextView name;        TextView age;        TextView sex;        TextView hobby;        ImageView img;    }
0 0
原创粉丝点击