0

我在我的应用中创建了 Facebook 群组时间线。我在 FB 组中有帖子,我将它们设置在 Android 的列表视图中,但是当我滚动列表视图时,我在列表项中丢失了第二张图片。我已经复制了我的图像加载器类,但没有任何改变。

滚动前

滚动前

滚动后

滚动后

这是我的适配器 getView 方法:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View vi = convertView;
    ViewHolder holder;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.announce_item, null);
        holder = new ViewHolder();
        holder.textTitle = (TextView) vi.findViewById(R.id.textView1);
        holder.image = (ImageView) vi.findViewById(R.id.imageView1);
        holder.attachimage=(ImageView)vi.findViewById(R.id.attachimage);
        holder.contentArea = (TextView) vi.findViewById(R.id.textView2);
        vi.setTag(holder);
    } else
        holder = (ViewHolder) vi.getTag();

    holder.textTitle.setText(sender.get(position));
    String content = contentMessage.get(position);
    holder.contentArea.setText(Html.fromHtml(content.replace("\n", "<br/>")+" "+type.get(position)));
    holder.image.setTag(profilePicture.get(position));
    imageLoader.DisplayImage(profilePicture.get(position), activity,
            holder.image);
    if(type.get(position).equals("photo"))
    {
        holder.attachimage.setTag(attach.get(position));
        imageLoader3.DisplayImage(attach.get(position),activity,holder.attachimage);
        System.out.println("To Loader: "+attach.get(position));
    }
    else
    {
        holder.attachimage.setVisibility(View.GONE);

    }
    return vi;
}
4

2 回答 2

1

你需要holder.attachimage在你的 if 条件下显示

if(type.get(position).equals("photo"))
{
    holder.attachimage.setVisibility(View.VISIBLE);// you need to make it visible here
    holder.attachimage.setTag(attach.get(position));
    imageLoader3.DisplayImage(attach.get(position),activity,holder.attachimage);
    System.out.println("To Loader: "+attach.get(position));
}
else
{
    holder.attachimage.setVisibility(View.GONE);

}

当您使用时,holder假设视图对于特定位置变得不可见。现在,当您尝试View再次访问它时,它将进入if条件并且所有内容都将被执行,但您将无法看到它,因为它的可见性已设置为View.GONE并且未设置回View.VISIBLE.

于 2014-01-31T10:10:42.763 回答
0
// try this way

1. Download AndroidQuery jar from here:

http://code.google.com/p/android-query/downloads/detail?name=android-query-full.0.25.10.jar.

2. Put this jar to your libs folder and right click on jar and Build Path -> Add to bulid path

3. How to use see this example:

AQuery androidQuery = new AQuery(this);

androidQuery.id(yourImageViewId).image("imageUrl", true, true);

// androidAQuery.id(img1).image(imageUrl, memeryCache, fileCache);

// memeryCache : if give url image in Android Query memmery cache then it will not again get from server so set true if you not want to get from server on each time
// fileCache : if give url image in  Android Query file cache then it will not again get from server so set true if you not want to get from server on each time (In case memmery is not free or enough than it cache in file if we gave fileCache true)
于 2014-01-31T10:19:10.750 回答