ListView使用ViewHolder提高性能

@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mHolder = null;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.item, null);
			mHolder = new ViewHolder();
			mHolder.name = (TextView) convertView.findViewById(R.id.tv_name);
			mHolder.phone = (TextView) convertView.findViewById(R.id.tv_phone);
			convertView.setTag(mHolder);
		} else {
			mHolder = (ViewHolder) convertView.getTag();
		}

		Person p = list.get(position);
		mHolder.name.setText(p.getName());
		mHolder.phone.setText(p.getPhone());

		return convertView;
	}

	class ViewHolder {
		TextView name;
		TextView phone;
	}

你可能感兴趣的:(ListView使用ViewHolder提高性能)