手记

listView优化示例代码

@Override

public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder;

if (convertView == null) {

holder = new ViewHolder();

convertView = View.inflate(getApplicationContext(),

R.layout.grid_item, null);

holder.iv = (ImageView) convertView

.findViewById(R.id.main_item_iv);

holder.tv = (TextView) convertView

.findViewById(R.id.main_item_tv_title);

convertView.setTag(holder);

} else {

holder = (ViewHolder) convertView.getTag();

}

holder.iv.setImageResource(item_icons[position]);

holder.tv.setText(item_names[position]);

return convertView;

}

}

class ViewHolder {

TextView tv;

ImageView iv;

}

原文链接:http://www.apkbus.com/blog-793998-61078.html

0人推荐
随时随地看视频
慕课网APP