BaseAdapter适配器view缓存

来源:互联网 发布:凸优化求解算法 编辑:程序博客网 时间:2024/06/02 06:05
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);}// 防止重复加载itemif (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() {@Overridepublic 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);elseimage.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;}

0 0
原创粉丝点击