How is it possible to make a smooth setSelection(position) for listFragment. For regular listviews it is possible to call smoothScrollToPosition(position) but this only works for api lvl 8 and above but this doesn’t matter because it doesn’t work for listfragment and not down to api lvl 7.
Any ideas, suggestions that will help implement this is greatly appreciated.
Mark D is correct that, if you want to smooth scroll the
ListViewin aListFragment, you need to callgetListView()on theListFragmentand then callsmoothScrollToPosition(int)on theListViewthat is returned. Of course, this only works down to API level 8 because that is whensmoothScrollToPosition(int)was introduced toAbsListView, the superclass ofListView.I suppose you could look at the code in
AbsListView.javato see what it does and try to replicate it in your own subclass ofAbsListVieworListView. It’s immediately clear thatsmoothScrollToPosition(pos)just callsstart(pos)on an instance of an inner classPositionScroller, but it looks somewhat complicated to replicate that behavior in your own subclass since thePositionScrollergets called from a several other spots likeonDetachedFromWindow(),public void onWindowFocusChanged(boolean hasWindowFocus). It’s not at all clear to me how you would cleanly integrate your PositionScroller behavior into your subclass based on the API 7 version ofAbsListView.If it were my decision, with API 7 and earlier making up less than 8% of devices accessing the Android Market in the latest data set, I’d just punt and do something simpler like
setSelectionFromTopwhenever the API is lower than 8 (detected by Build.VERSION.SDK_INT).