public class FoodListAdapter extends ArrayAdapter<ListFoodItem> { private ListView listView;
private AsyncImageLoader asyncImageLoader; public FoodListAdapter(Activity activity, List<ListFoodItem> foodList, ListView listView) {

super(activity, 0, foodList);
this.listView = listView;
asyncImageLoader = new AsyncImageLoader();
}
public View getView(int position, View convertView, ViewGroup parent) {
Activity activity = (Activity) getContext(); View rowView = convertView;
ViewCache viewCache;
if (rowView == null) {
LayoutInflater inflater = activity.getLayoutInflater();
rowView = inflater.inflate(R.layout.layout_eatingwhat_list_row, null);
viewCache = new ViewCache(rowView);
rowView.setTag(viewCache);
} else {
viewCache = (ViewCache) rowView.getTag();
}
ListFoodItem listFoodItem = getItem(position);

                           //下面是动态加载每一行的一个图片  
String imageUrl = listFoodItem.getImageUrl();
ImageView imageView = viewCache.getImageView();
imageView.setTag(imageUrl);
Drawable cachedImage = asyncImageLoader.loadDrawable(imageUrl, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
ImageView imageViewByTag = (ImageView) listView.findViewWithTag(imageUrl);
if (imageViewByTag != null) {
if(imageDrawable!=null){
imageViewByTag.setImageDrawable(imageDrawable);
}else{
imageViewByTag.setImageResource(R.drawable.eat_info_img_02_no);
}
}


}
});
if (cachedImage == null) {
imageView.setImageResource(R.drawable.eatwhat_list_common);
} else {
imageView.setImageDrawable(cachedImage);
}
TextView titleView = viewCache.getTitleView();
titleView.setText(listFoodItem.getTitleText()); TextView contentView = viewCache.getContentView();
contentView.setText(listFoodItem.getContentText()); return rowView;
} }  我传进来多少位的数组  就显示双倍的   尴尬  求解

解决方案 »

  1.   

    不是数组  说错了  就是里面封装了一个列对象的Arraylist
      

  2.   

    你没重写 getCount 函数?
      

  3.   

    我这个ListVIew  得有滑动加载功能  我要是重写了 不就挂了嘛。。  其他的都没什么问题   主要就是为什么我传一个10个对象的list   他给我显示20列数据  显示了两遍
      

  4.   

    怎么会挂呀?这个adapter 是 根据 getCount() 来计算到底 需要产生多少个view    public int getCount() {
            foodList.size();
        }
      

  5.   

    我大致说一下   我这个是从服务器DOWN的来的   一下20条  要是按你这么写的话  只能显示20条  因为我每次查 list对象里面的数据就会换的  我现在想知道这个getCount方法是什么时候调用的  是第一次调用的  还是用notifyDataSetChanged()的时候也能够调用一下   我这个listview数量会逐渐增加  而传进来的arraylist始终都是20条  如果通过你这种重写的方法的话  当我滚动出发加载的时候  还会掉用这个getCount方法吗?   最好是能直接解决我这个重复显示的问题  明明传的是20个  为什么重复显示两遍变成40个呢
      

  6.   

    哦了 解决了   另外getCount方法是每次一调用getView方法就调用一次的