+
+ /*
+ * Restore index and position
+ */
+ protected void restoreIndexAndTopPosition() {
+ if (mIndexes.size() > 0) {
+ // needs to be checked; not every browse-up had a browse-down before
+
+ int index = mIndexes.remove(mIndexes.size() - 1);
+
+ int firstPosition = mFirstPositions.remove(mFirstPositions.size() -1);
+
+ int top = mTops.remove(mTops.size() - 1);
+
+ mList.setSelectionFromTop(firstPosition, top);
+
+ // Move the scroll if the selection is not visible
+ int indexPosition = mHeightCell*index;
+ int height = mList.getHeight();
+
+ if (indexPosition > height) {
+ if (android.os.Build.VERSION.SDK_INT >= 11)
+ {
+ mList.smoothScrollToPosition(index);
+ }
+ else if (android.os.Build.VERSION.SDK_INT >= 8)
+ {
+ mList.setSelectionFromTop(index, 0);
+ }
+
+ }
+ }
+ }
+
+ /*
+ * Save index and top position
+ */
+ protected void saveIndexAndTopPosition(int index) {
+
+ mIndexes.add(index);
+
+ int firstPosition = mList.getFirstVisiblePosition();
+ mFirstPositions.add(firstPosition);
+
+ View view = mList.getChildAt(0);
+ int top = (view == null) ? 0 : view.getTop() ;
+
+ mTops.add(top);
+
+ // Save the height of a cell
+ mHeightCell = (view == null || mHeightCell != 0) ? mHeightCell : view.getHeight();
+ }
+
+