Android ListView利用好convertView

 public View getView(int position, View convertView, ViewGroup parent) {
	ViewHolder holder = null;
	if (convertView == null) {
		holder=new ViewHolder(); 
		convertView = mInflater.inflate(R.layout.vlist2, null);
		holder.img = (ImageView)convertView.findViewById(R.id.img);
		holder.title = (TextView)convertView.findViewById(R.id.title);
		holder.info = (TextView)convertView.findViewById(R.id.info);
		holder.viewBtn = (Button)convertView.findViewById(R.id.view_btn);
		convertView.setTag(holder);
	}else {
		holder = (ViewHolder)convertView.getTag();
	}
	holder.img.setBackgroundResource((Integer)mData.get(position).get("img"));
	holder.title.setText((String)mData.get(position).get("title"));
	holder.info.setText((String)mData.get(position).get("info"));
	return convertView;
}
  getView 的时候最好利用好convertView 效率会提高不少。

你可能感兴趣的:(android)