一个listview项目中的两个图像

时间:2014-01-31 10:07:50

标签: android listview lazylist

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

滚动前

Before Scroll

滚动后

After Scroll

这是我的适配器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;
}

2 个答案:

答案 0 :(得分:1)

您需要在if条件中显示holder.attachimage,例如

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

答案 1 :(得分: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)