我使用适配器,ListView
这是实现getView
@Override
public View getView(int position, View convertView, ViewGroup parent){
ItemViewHolder viewHolder;
if(convertView == null){
convertView = (RelativeLayout)inflater.inflate(resource,parent, false);
viewHolder = new ItemViewHolder();
viewHolder.itemTextName = (TextView)convertView.findViewById(R.id.item_name);
viewHolder.itemTextExpDate = (TextView)convertView.findViewById(R.id.item_exp_date);
viewHolder.itemImage = (ImageView)convertView.findViewById(R.id.item_image);
}
else{
viewHolder = (ItemViewHolder)convertView.getTag();
}
Item item = listItem.get(position);
if(listItem != null){
viewHolder.itemTextName.setText(item.getName());
viewHolder.itemTextExpDate.setText(""+item.getDaysleft());
viewHolder.itemImage.setImageBitmap(item.getImage());
}
return convertView;
}
static class ItemViewHolder {
View baseView;
TextView itemTextName;
TextView itemTextExpDate;
ImageView itemImage;
}
当我设置Bitmap
为ImageView
不ListView
流畅。
我是否实现了正确的代码getView
?