每次向下滚动时,毕加索都会更改图像

android listview imageview adapter

257 观看

1回复

8 作者的声誉

有一个列表视图,其中我在运行时获取图像。图像的获取是使用毕加索库完成的。

但是,每当我滚动时,图像就会变得混乱。我不知道是什么问题。请帮助。代码如下。

public class Feed_Adapter extends ArrayAdapter {
Context ctx;
private List<Feed_List> list =new ArrayList<Feed_List>();
Feed_Adapter(Context context,int resources)
{
    super(context,resources);
    ctx=context;
}

public ArrayList<Feed_List> getList()
{
    return (ArrayList<Feed_List>) list;
}
public void add(ArrayList<Feed_List> object )
{
    super.add(object);
    list=object;
}
public void add(Feed_List object)
{
    super.add(object);
    list.add(object);
}public void insert(Feed_List obj,int pos)
{
    super.insert(obj,pos);
    list.add(pos,obj);
}

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

@Nullable
@Override
public Object getItem(int position) {
    return list.get(position);
}

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row;
    row=convertView;

    if(row==null)
    {
        final Question_Holder question_holder;
        LayoutInflater layoutinflator=(LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row=layoutinflator.inflate(R.layout.feed_row,parent,false );
        question_holder= new Question_Holder();
        question_holder.que_image=(ImageView) row.findViewById(R.id.iv_feed_row_que_image);
        row.setTag(question_holder);
    }

    else
    {
        final Question_Holder question_holder= (Question_Holder)row.getTag();
    }

    final ImageView circleImageView=question_holder.que_image;
    if(list.get(position).getImage_status().equals("1")) {

        Picasso.with(ctx).load("url" + list.get(position).getQuestion_id()).placeholder(circleImageView.getDrawable()).into(circleImageView);
    }
    else
    {
        //question_holder.que_image.setVisibility(View.INVISIBLE);
    }

    return row;
}



static class Question_Holder
{
    ImageView que_image;
}

}

作者: vivek kumar 的来源 发布者: 2017 年 3 月 11 日

回应 1


0

185 作者的声誉

决定

这是ListView的问题。我强烈建议您使用recyclerview。尝试;

public class FeedAdapter
        extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
    private Context context;
    private final List<Feed> feedList;

    public FeedAdapter(Context context, List<Feed> feeds) {
        this.context = context;
        this.feedList = feeds;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.feed_list_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.mItem = feedList.get(position);

        if (holder.mItem.getImageStatus().equals("1"))
            Picasso.with(context).load(holder.mItem.getQuestionId()).into(holder.something);
        else{
            ////
        }

    }

    @Override
    public int getItemCount() {
        return feedList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        public final View view;

        @BindView(R.id.something)
        ImageView something;
        Feed mItem;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            this.view = view;
        }
    }

}
作者: msecilmis 发布者: 2017 年 3 月 11 日
32x32