ListView控件更改项目中滚动时控件、项目、ListView

2023-09-06 14:48:30 作者:╰╰︶只想靜靜的生活

我使用的是自定义的ArrayAdapter来填充列表实施ListFragment。每一行项目都有一个ImageView的和三个TextViews。数据正在通过XML解析,图像被异步加载。

I am implementing a ListFragment using a custom ArrayAdapter to populate the list. Each row item has an ImageView and three TextViews. Data is being parsed via XML and the images are being async loaded.

我遇到的问题是,ListView的填充和看起来不错,但滚动时有问题。我可以一次在屏幕上显示7项。当我滚动到8日,它突然变化,因此应出现的下一行。它只做它行8(即行8,16,24,等等)整除。

The problem I am having is that the ListView populates and looks good, but there is a problem when scrolling. I can fit 7 items on the screen at once. When I scroll to the 8th, it changes suddenly so the next row that should be appearing. It only does it on rows divisible by 8 (ie. rows 8, 16, 24, etc).

我使用的是ViewHolder模式,以确保与这个ListView的速度不错。我想,问题就出在那里的地方,但我已经搜索周围,似乎我做正确这个模式,我已经跑出来的东西,以解决此问题进行检查。我究竟做错了什么?谢谢!

I'm using the ViewHolder pattern to ensure good speed with this ListView. I figure the problem lies in there somewhere, but I have searched around and it appears I am doing this pattern correctly and I have run out of things to check in order to resolve this issue. What am I doing wrong? Thanks!

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    MyViewHolder holder;
    if (row == null) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        row = inflater.inflate(R.layout.browse_result_list_item, null, false);
        holder = new MyViewHolder();
        holder.adTitle = (TextView) row.findViewById(R.id.adTitle);
        holder.region = (TextView) row.findViewById(R.id.region);
        holder.time = (TextView) row.findViewById(R.id.time);
        holder.thumbnail = (ImageView) row.findViewById(R.id.browseThumbnail);
        row.setTag(holder);
    } else {
        holder = (MyViewHolder) row.getTag();
    }
    SearchResult result = mObjects.get(position);

    holder.adTitle.setText(result.getTitle().substring(0, result.getTitle().length()-3)); // three ... at the end, remove them
    holder.region.setText(result.getRegion());
    holder.time.setText(result.getPostingTime());

    // Download the image thumbnail
    ArrayList<String> urls = result.getImageUrls();
    if (urls.size() > 0)
        download(urls.get(0), holder.thumbnail);
    else // No image for this post, put a placeholder
        holder.thumbnail.setImageResource(R.drawable.ic_action_picture);

    return row;
}

private static class MyViewHolder {
    public static TextView adTitle;
    public static TextView region;
    public static TextView time;
    public static ImageView thumbnail;
}

编辑:我找到了solution感谢@frozenkoi。最终被ViewHolder导致问题里面的静态变量。他们现在只是公众和类是静态的,这个问题已经解决了蜂

I found the solution thanks to @frozenkoi. Ended up being the static variables inside the ViewHolder causing problems. They are now simply public and the class is static and the issue has bee solved.

推荐答案

我找到了解决办法感谢@frozenkoi。最终被ViewHolder导致问题里面的静态变量。他们现在只是公众和类是静态的,这个问题已经解决了蜂

I found the solution thanks to @frozenkoi. Ended up being the static variables inside the ViewHolder causing problems. They are now simply public and the class is static and the issue has bee solved.

private static class MyViewHolder {
    public TextView adTitle;
    public TextView region;
    public TextView time;
    public ImageView thumbnail;
}
 
精彩推荐