Do not recyle headers and footers when measuring the ListView.
Bug #2461893

This was causing headers and footers to be in a wrong state after the first
recycling pass, which would cause them to be detached from the window. This
was in turn preventing invalidate operations from performing successfully.
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index a9b746a..bec62b1 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -4155,9 +4155,9 @@
             final View[] activeViews = mActiveViews;
             for (int i = 0; i < childCount; i++) {
                 View child = getChildAt(i);
-                AbsListView.LayoutParams lp = (AbsListView.LayoutParams)child.getLayoutParams();
+                AbsListView.LayoutParams lp = (AbsListView.LayoutParams) child.getLayoutParams();
                 // Don't put header or footer views into the scrap heap
-                if (lp != null && lp.viewType != AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
+                if (lp != null && lp.viewType != ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
                     // Note:  We do place AdapterView.ITEM_VIEW_TYPE_IGNORE in active views.
                     //        However, we will NOT place them into scrap views.
                     activeViews[i] = child;
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index 51a1ef2..912dd5e 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -138,7 +138,7 @@
 
     // the single allocated result per list view; kinda cheesey but avoids
     // allocating these thingies too often.
-    private ArrowScrollFocusResult mArrowScrollFocusResult = new ArrowScrollFocusResult();
+    private final ArrowScrollFocusResult mArrowScrollFocusResult = new ArrowScrollFocusResult();
 
     public ListView(Context context) {
         this(context, null);
@@ -1040,7 +1040,8 @@
             childWidth = child.getMeasuredWidth();
             childHeight = child.getMeasuredHeight();
 
-            if (recycleOnMeasure()) {
+            if (recycleOnMeasure() && mRecycler.shouldRecycleViewType(
+                    ((LayoutParams) child.getLayoutParams()).viewType)) {
                 mRecycler.addScrapView(child);
             }
         }
@@ -1155,7 +1156,8 @@
             }
 
             // Recycle the view before we possibly return from the method
-            if (recyle) {
+            if (recyle && recycleBin.shouldRecycleViewType(
+                    ((LayoutParams) child.getLayoutParams()).viewType)) {
                 recycleBin.addScrapView(child);
             }