Question

I've made a Facebook group timeline in my app. I've got posts in a FB group and I set them on a listview in Android but when I scroll listview, I lost my second images in list item. I 've duplicated my image loader class but nothing has changed.

Before Scroll

Before Scroll

After Scroll

After Scroll

Here is my adapter getView method:

@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;
}
Was it helpful?

Solution

You need to make holder.attachimage visible in your if condition like

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);

}

As you are using holder suppose the view becomes invisible for a particular position. Now when you try to access that View again it will go into the if condition and everything will be executed but you won't be able to see it as its visibility was set to View.GONE and it was not set back to View.VISIBLE.

OTHER TIPS

// 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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top