Android picasso imageloader listview项目图像交换

时间:2016-04-23 12:30:24

标签: android listview picasso

我正在使用picasso库来加载listview中的图像以便快速加载图像它工作正常,但是当我们滚动listview图像进行交换时。

请参考以下代码,让我知道我哪里出错了

public static class ViewHolder {
        @Bind(R.id.userNameTV)
        TextView _userNameTV;
        @Bind(R.id.addCB)
        CheckBox _addCB;
        @Bind(R.id.userIV)
        ImageView _userIV;
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
@Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;

        if (convertView == null) {

            convertView = inflater.inflate(R.layout.add_participants_row, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        AddparticipantsBean bean = _addArrayList.get(position);


        if(bean.get_userName() != null){
            viewHolder._userNameTV.setText(bean.get_userName());
        }else
            viewHolder._userNameTV.setText("");

        viewHolder._userNameTV.setTypeface(Constant.typeface(context, "HelveticaNeueLTStd-LtCn.otf"));

        if(bean.get_userImage().equalsIgnoreCase("null")||bean.get_userImage().equalsIgnoreCase("")){
            viewHolder._userIV.setBackgroundResource(R.drawable.icon);
        }else {

            Picasso.with(this.context).cancelRequest(viewHolder._userIV);

            Picasso.with(context)
                    .load(_addArrayList.get(position).get_userImage())

                    .placeholder(R.drawable.icon) // optional
                    .error(R.drawable.icon)         // optional
                    .into(new Target() {

                        //   @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                        @SuppressLint("NewApi")
                        @Override
                        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                            viewHolder._userIV.setBackground(new BitmapDrawable(context.getResources(), bitmap));
                        }

                        @Override
                        public void onBitmapFailed(final Drawable errorDrawable) {
                            Log.d("TAG", "FAILED");
                        }

                        @Override
                        public void onPrepareLoad(final Drawable placeHolderDrawable) {
                            Log.d("TAG", "Prepare Load");
                        }
                    });




            // viewHolder._userIV.setBackgroundResource(R.drawable.img_1);
        }


        viewHolder._addCB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AddparticipantsBean bean = new AddparticipantsBean();
                bean = _addArrayList.get(position);

                if(bean.get_isChecked()){
                    bean.set_isChecked(false);
                }else {
                    bean.set_isChecked(true);
                }
                notifyDataSetChanged();

            }
        });

        viewHolder._addCB.setChecked(bean.get_isChecked());

        return convertView;
    }

0 个答案:

没有答案