您的位置:首页 > 其它

BaseAdapter适配器view缓存

2015-11-13 17:10 357 查看
public View getView(int position, View convertView, ViewGroup parent) {
final ContentData data = activity.getCommonalityInfo().getRecommendData().getDatas().get(position);
HashMap<String, View> tag;
if (convertView == null || (tag = (HashMap<String, View>) convertView.getTag()) == null) {
convertView = View.inflate(activity, R.layout.dialog_item_video_about, null);
tag = new HashMap<String, View>();
tag.put("image", convertView.findViewById(R.id.iv_icon));
tag.put("title", convertView.findViewById(R.id.tv_title));
tag.put("timeLength", convertView.findViewById(R.id.tv_timeLength));
convertView.setTag(tag);
}

// 防止重复加载item
if (parent.getHeight() != 0) {
final ImageView image = (ImageView) tag.get("image");
String imgUrl = Public.addParamsToImageUrl(data.getHorizontalPic(), Public.dip2px(activity, 100), Public.dip2px(activity, 75));
image.setTag(imgUrl);
Bitmap bitmap = activity.getAsyncImage().loadImage(imgUrl, new ImageCallback() {

@Override
public void imageLoaded(Bitmap bitmap, String imageUrl) {
if (busy) {
return;
}
if (bitmap != null) {
if (imageUrl.equals(image.getTag().toString()))
image.setImageBitmap(bitmap);
}
}
});

if (bitmap != null)
image.setImageBitmap(bitmap);
else
image.setImageResource(R.drawable.nodata);

((TextView) tag.get("title")).setText(data.getName());
String timeLength = "";

if (null != data.getDuration()) {
timeLength = QLStringUtils.generateTime(1000 * Integer.parseInt(data.getDuration()));;
}

((TextView) tag.get("timeLength")).setText("时长:" + timeLength);
}
return convertView;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: