0

我正在使用一个listview st,每行都有一个imageview和一个flowlayout,我扩展了baseadapter并向它发送了一个hashmap的arraylisy,每个都有图像路径和一个单词列表我的问题是每次我向上滚动一个条目“叶子” 屏幕然后向下,条目“返回”到屏幕 条目流程布局中被回收的单词正在被复制(这意味着如果键上磁盘旁边的单词是“dok”,那么在我向下滚动之后然后再次向上流动布局中的单词现在是“dok dok”)......我不知道为什么...... =(

我从这里把flowlayout +气泡带到了它 - http://www.superliminal.com/sources/FlowLayout.java.html http://nishantvnair.wordpress.com/2010/09/28/android-create-bubble-喜欢脸书/

和一个解码异步任务,将图像从@MCeley 的答案加载到列表中 - Large ListView contains images in Android

那是我的 getView 代码-

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = null;
    FlowLayout flowLayout = null;
    if (convertView == null) {
        convertView = layoutInflater.inflate(R.layout.list_item, null);
        imageView = (ImageView) convertView.findViewById(R.id.list_image);
        flowLayout = (FlowLayout) convertView.findViewById(R.id.flow_tags);
    } else {
        imageView = (ImageView) convertView.findViewById(R.id.list_image);
        flowLayout = (FlowLayout) convertView.findViewById(R.id.flow_tags);
        DecodeTask task = (DecodeTask) imageView.getTag(R.id.list_image);
        if (task != null) {
            task.cancel(true);
        }
    }
    HashMap<String, List<String>> photos = new HashMap<String, List<String>>();
    photos = data.get(position);
    imageView.setImageBitmap(null);
    DecodeTask task = new DecodeTask(imageView);
    task.execute(photos.get(DatabaseHandler.KEY_PATH).get(0));
    imageView.setTag(R.id.list_image, task);

    ArrayList<String> subjects = new ArrayList<String>();
    int size = photos.get(DatabaseHandler.KEY_TAGS).size();
    for (int i = 0; i < size; i++) {
        String name = String.format("name - %s ",
                photos.get(DatabaseHandler.KEY_TAGS).get(i));
        Bubble.getBubble(name, flowLayout, subjects, activity,
                photos.get(DatabaseHandler.KEY_PATH).get(0), false, false);
    }

    return convertView;
}

TNX提前..!

4

2 回答 2

0

尝试为您的视图使用持有者,即 ImageView 和 flowLayout。

   ViewHolder holder;            
       // When convertView is not null, we can reuse it directly, there is no need            
       // to reinflate it. We only inflate a new View when the convertView supplied            
       // by ListView is null.            

       if (convertView == null) {                

        convertView = mInflater.inflate(R.layout.sample, null);   
        // Creates a ViewHolder and store references to the two children views                
        // we want to bind data to.               
        holder = new ViewHolder();                
        holder.imageview= (ImageView) convertView.findViewById(R.id.list_image);               
        holder.flowLayout= (FlowLayout) convertView.findViewById(R.id.flow_tags);                
        convertView.setTag(holder);            
       } else {                
        // Get the ViewHolder back to get fast access to the FlowLayout
        // and the ImageView.


        holder = (ViewHolder) convertView.getTag();

       } 

创建viewHolder

static class viewHolder(){

        ImageView imageview;
        FlowLayout flowlayout;

}
于 2013-09-10T12:11:49.663 回答
0

在您的适配器中使用此代码。如果不为空,则应重新使用该行并删除重复的行。

 @Override
public View getView(int position, View convertView, ViewGroup parent) {

    // A ViewHolder keeps references to children views to avoid unneccessary
    // calls
    // to findViewById() on each row.
    ViewHolder holder;
    // When convertView is not null, we can reuse it directly, there is no
    // need
    // to reinflate it. We only inflate a new View when the convertView
    // supplied
    // by ListView is null.

    if (convertView == null) {

        convertView = mInflater.inflate(R.layout.sample, null);
        // Creates a ViewHolder and store references to the two children
        // views
        // we want to bind data to.
        holder = new ViewHolder();
        holder.name = (TextView) convertView.findViewById(R.id.text);
        holder.icon = (ImageView) convertView.findViewById(R.id.icon);
        convertView.setTag(holder);
    } else {
        // Get the ViewHolder back to get fast access to the TextView
        // and the ImageView.

        holder = (ViewHolder) convertView.getTag();

    }

    // Bind the data efficiently with the holder.
    holder.name.setText(myElements.get(id));
    holder.icon.setImageBitmap(mIcon1);

    return convertView;
}

static class ViewHolder {
    TextView  name;
    ImageView icon;
}
于 2013-09-10T15:27:08.020 回答