listview getView()方法,图片超范围加载

这是  在getview()方法中 加载图片 的模块,但是我用图片选择器选择一张图片,转换成字符流,存到集合里,上传到服务器。在适配器中读取集合中的字符流,显示在imageview中。


为什么我上传了一张,缺显示了很多,打了断点,就是上传一张,但是 为什么显示了多张  》呜呜呜呜~~~~~~~~~


这是 getview()方法中,加载图片的模块,到底该怎么解决那?

int a=data.getPhoto().size();

ImageView[] imageViews = new ImageView[a];

for (int j = 0; j <a; j++) {
    final ImageView imageView = new ImageView(mContext);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(UtilTools.getWidth(mContext)/2, UtilTools.getHeight(mContext)/2));
    UtilTools.getImage(mContext,imageView,data.getPhoto().get(j));
    imageViews[j] = imageView;
    viewHolder1.ll_ll.addView(imageViews[j]);
}



这是整个适配器的代码

public class SellAdapter extends BaseAdapter implements View.OnClickListener {
    private Context mContext;
    private List<Sell> mList;
    //布局加载器
    private LayoutInflater inflater;
    private Sell data;

        private Callback mCallback;


           /**

            * 自定义接口,用于回调按钮点击事件到Activity

            * @author Ivan Xu

            * 2014-11-26

            */





           public interface Callback {

               public void click(View v);

           }




    public SellAdapter(Context mContext, List<Sell> mList, Callback callback) {
        this.mContext = mContext;
        this.mList = mList;
        mCallback = callback;
        //获取系统服务
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder1=null;
        //如果是第一次加载
        if(view==null){
            viewHolder1=new ViewHolder();
            view=inflater.inflate(R.layout.item_sell,null);

            viewHolder1.iv_logo=(ImageView) view.findViewById(R.id.sell_item_logo);
            viewHolder1.tv_name=(TextView)view.findViewById(R.id.sell_item_name);
            viewHolder1.tv_title=(TextView)view.findViewById(R.id.sell_item_title);
            viewHolder1.tv_content=(TextView)view.findViewById(R.id.sell_item_content);
            viewHolder1.iv_message=(ImageView) view.findViewById(R.id.sell_item_message);
            viewHolder1.ll_ll=(LinearLayout) view.findViewById(R.id.sell_item_ll);


            //设置缓存
            view.setTag(viewHolder1);
        }
        else {
            viewHolder1 = (ViewHolder)view.getTag();
        }



        //设置数据
        data=mList.get(i);
        viewHolder1.tv_name.setText(data.getName());
        viewHolder1.tv_title.setText(data.getTitle());
        viewHolder1.tv_content.setText(data.getContent());


        viewHolder1.iv_message.setOnClickListener(this);
        viewHolder1.iv_message.setTag(i);

        if (data.getImage()!=null){
            UtilTools.getImage(mContext,viewHolder1.iv_logo,mList.get(i).getImage());
        }

//        list!=null && !list.isEmpty()

            int a=data.getPhoto().size();

            ImageView[] imageViews = new ImageView[a];

            for (int j = 0; j <a; j++) {
                final ImageView imageView = new ImageView(mContext);
                imageView.setLayoutParams(new LinearLayout.LayoutParams(UtilTools.getWidth(mContext)/2, UtilTools.getHeight(mContext)/2));
                UtilTools.getImage(mContext,imageView,data.getPhoto().get(j));
                imageViews[j] = imageView;
                viewHolder1.ll_ll.addView(imageViews[j]);
            }



        //将逻辑改成必须添加图片,就不用考虑这部分了


//        else {
//            //还是加个什么吧,要不然的话,老崩溃,我也不知道为什么
//            //稍微加点东西,让人感觉不到,不可见就OK了
//
//            TextView t=new TextView(mContext);
//            t.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,2));
//            t.setVisibility(View.INVISIBLE);
//            viewHolder1.ll_ll.addView(t);
//
//
//
//
//        }





        return view;
    }

    //响应按钮点击事件,调用子定义接口,并传入View
    @Override
    public void onClick(View view) {
        mCallback.click(view);
    }


    class ViewHolder{
        private LinearLayout ll_ll;
        private ImageView iv_logo;
        private TextView tv_name;
        private TextView tv_title;
        private TextView tv_content;
        private  ImageView iv_message;
    }










}




该怎么解决那?大家帮帮忙呗~~~~~~~~~

蒲公英wsg
浏览 1651回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android