我有一个物品清单。其中有名称、价格和产品图片网址。我使用https://github.com/nostra13/Android-Universal-Image-Loader 这个库从 url 加载 imageview。我面临的问题是 listview 在某些行不显示图像
public class BagAdapter extends BaseAdapter {
int pos;
Context MyContext;
public boolean isCloseButtonAvailable;
Object positionForCheck;
ViewHolderForBag holder;
public BagAdapter(Context _MyContext, boolean isavail) {
MyContext = _MyContext;
isCloseButtonAvailable = isavail;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return BagList.getItemCount();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View MyView = convertView;
pos = position;
positionForCheck = (Object) pos;
if (convertView == null) {
LayoutInflater li = (LayoutInflater) MyContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
MyView = li.inflate(R.layout.shoppingbagrow, null);
holder = new ViewHolderForBag();
holder.listitemimageView = (ImageView) MyView
.findViewById(R.id.listitemimageView);
holder.name = (TextView) MyView
.findViewById(R.id.DescriptionTextView);
holder.price = (TextView) MyView.findViewById(R.id.PriceTextView);
holder.arrowimage = (ImageView) MyView
.findViewById(R.id.Arrowimagelistitem);
holder.editimage = (ImageView) MyView.findViewById(R.id.editimage);
holder.border = (ImageView) MyView
.findViewById(R.id.listitemimageView);
MyView.setTag(holder);
} else {
holder = (ViewHolderForBag) MyView.getTag();
}
String producturl="";
Typeface type= Typeface.createFromAsset(MyContext.getAssets(),"fonts/Helvetica.ttf");
holder.name.setText("$"
+ BagList.getAllBaglistItems().get(pos).itemName);
holder.price.setText("$"
+ BagList.getAllBaglistItems().get(pos).itemPrice);
Double d=Double.parseDouble(BagList.getAllBaglistItems().get(pos).itemPrice.toString());
producturl=String.valueOf(BagList.getAllBaglistItems().get(pos).itemUrl.toString());
holder.price.setText( String.format("%.2f", d) );
holder.price.setTypeface(type, Typeface.BOLD);
holder.name.setTypeface(type, Typeface.BOLD);
holder.arrowimage.setImageResource(R.drawable.aero);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(MyContext));
imageLoader.displayImage(producturl, holder.listitemimageView );
holder.editimage.setTag(pos);
if ((position + 1) % 3 == 0)
holder.border.setVisibility(View.INVISIBLE);
else
holder.border.setVisibility(View.VISIBLE);
if (isCloseButtonAvailable) {
holder.editimage.setVisibility(View.VISIBLE);
holder.editimage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DatabaseAdapterForBag dbBag = new DatabaseAdapterForBag(
MyContext);
dbBag.open();
int posi = Integer.parseInt(v.getTag().toString());
dbBag.deleteFile(BagList.getAllBaglistItems().get(posi).itemSku);
dbBag.close();
BagList.deleteItem(posi);
notifyDataSetChanged();
}
});
} else {
holder.editimage.setVisibility(View.GONE);
}
return MyView;
}
public static class ViewHolderForBag {
// public ImageView listitemimageView;
public TextView name;
public TextView price;
public ImageView border;
public ImageView arrowimage;
public ImageView editimage;
public ImageView listitemimageView;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return BagList.getAllBaglistItems().get(position);
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
这是我的适配器类。我在哪里做错了?