diff --git a/src/com/fsck/k9/view/K9PullToRefreshListView.java b/src/com/fsck/k9/view/K9PullToRefreshListView.java index 58a1024bb..5909bc624 100644 --- a/src/com/fsck/k9/view/K9PullToRefreshListView.java +++ b/src/com/fsck/k9/view/K9PullToRefreshListView.java @@ -1,6 +1,7 @@ package com.fsck.k9.view; import android.content.Context; +import android.graphics.Canvas; import android.os.Parcelable; import android.util.AttributeSet; import android.widget.ListView; @@ -28,6 +29,31 @@ public class K9PullToRefreshListView extends PullToRefreshListView { */ layoutChildren(); } + + @Override + protected void dispatchDraw(Canvas canvas) { + if (getAdapter() != null) { + int count = getChildCount(); + int itemCount = getAdapter().getCount(); + + /* + * 2013-03-18 - cketti + * + * Work around a bug in ListView (?) that leads to a crash deep inside the + * framework code. + * I didn't track down the exact cause of this. My best guess is that we change + * the data (remove items) while the ListView isn't visible. Probably because + * the view is hidden, layoutChildren() is never called and when this method + * runs the layout contains more item views than the adapter contains elements + * and bad things(tm) happen. + */ + if (itemCount < count) { + layoutChildren(); + } + } + + super.dispatchDraw(canvas); + } }; } }