我已經在我的應用程序中製作了Facebook組時間軸。我有一個FB組的帖子,我將它們設置在Android的listview中,但是當我滾動listview時,我在列表項中丟失了第二張圖像。我重複了我的圖像加載器類,但沒有任何改變。在一個listview項目中的兩個圖像
滾動之前
後滾動
這裏是我的適配器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;
}
+1。用簡單的話來說,因爲當它不是照片時你使用setVisibility(GONE),所以如果它是一張照片,你必須設置可見性(VISIBLE)。 –