From 5e8f9bbef6348926d5790c473c9cea1eae398896 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Fri, 17 Feb 2017 22:17:46 +0100 Subject: [PATCH] be explicit about the current scrolling position Jump to top if we have no LRU cache entry --- .../android/vanilla/LibraryPagerAdapter.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java b/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java index b5d1f2ff..069bd669 100644 --- a/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java +++ b/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java @@ -652,11 +652,14 @@ public class LibraryPagerAdapter int index = message.arg1; mAdapters[index].commitQuery(message.obj); - // Restore scrolling position if present and valid Integer curPos = sLruAdapterPos.popPosition(mAdapters[index]); - if (curPos != null && curPos < mLists[index].getCount()) - mLists[index].setSelection(curPos); + if (curPos == null || curPos >= mLists[index].getCount()) { + // we got no cached data or it is out of bounds + curPos = 0; + } + // curPos is now either 0 or a cached position -> jump to this position + mLists[index].setSelection(curPos); break; } case MSG_SAVE_SORT: {