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
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;
}
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
.