【问题标题】:Two images in one listview item一个列表视图项中的两个图像
【发布时间】:2014-01-31 10:07:50
【问题描述】:

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

滚动前

滚动后

​​>

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

【问题讨论】:

    标签: android listview lazylist


    【解决方案1】:

    你需要让holder.attachimage 在你的 if 条件中可见

    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。简单来说,因为你在不是照片时使用 setVisibility(GONE),所以如果是照片,你必须 setVisibility(VISIBLE)。
    【解决方案2】:
    // 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-24
      • 2016-02-13
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      相关资源
      最近更新 更多