How to clear the views which are held in the ListView's RecycleBin?

后端 未结 5 1230
梦如初夏
梦如初夏 2020-12-03 17:23

In Android\'s ListView widget, the ListView will hold the views which is got from getView method of an Adapter in a inner class

5条回答
  •  执笔经年
    2020-12-03 17:57

    In my opinion @nekavally offers the best solution. I have a ListView and a SimpleCursorAdapter. Sometimes I need to change the size of the list items. But since the adapter recycles the views, they may appear in the wrong way. So I'm just calling mListView.invalidateViews() after reclaiming the recycled views, and it works just fine.

    startAnimation(initialHeight, finalHeight, duration, new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            childView.getLayoutParams().height = 
                                    (Integer) animation.getAnimatedValue();
                            childView.requestLayout();
    
                            if (animation.getAnimatedFraction() == 1f) {
                                mListView.reclaimViews(new ArrayList());
                                mListView.invalidateViews();
                            }
                        }
                    });
    

提交回复
热议问题