2014-01-31 60 views
0

我已經在我的應用程序中製作了Facebook組時間軸。我有一個FB組的帖子,我將它們設置在Android的listview中,但是當我滾動listview時,我在列表項中丟失了第二張圖像。我重複了我的圖像加載器類,但沒有任何改變。在一個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; 
} 

回答

1

你需要讓holder.attachimage可見在你我f條件,如

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

+1。用簡單的話來說,因爲當它不是照片時你使用setVisibility(GONE),所以如果它是一張照片,你必須設置可見性(VISIBLE)。 –

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) 
相關問題