Android, how to make animated setSelection () for listfragment?

How can I make a smooth setSelection (position) for listFragment. For regular lists, you can call smoothScrollToPosition (position), but this only works for api lvl 8 and above, but it does not matter because it does not work for listfragment, not api lvl 7.

Any ideas, suggestions that will help implement this are greatly appreciated.

+5
source share
2 answers

The D sign is correct, if you want to smooth the scroll ListViewin ListFragment, you need to call getListView()in ListFragment, and then call smoothScrollToPosition(int)on ListView, which is back. Of course, this only works up to API level 8, because when it smoothScrollToPosition(int)was introduced to AbsListView, it was a superclass ListView.

, AbsListView.java, , , AbsListView ListView. , smoothScrollToPosition(pos) start(pos) PositionScroller, , PositionScroller , onDetachedFromWindow(), public void onWindowFocusChanged(boolean hasWindowFocus). , PositionScroller API 7 AbsListView.

, API 7 8% , Android Market, , punt - , setSelectionFromTop, API 8 ( Build.VERSION.SDK_INT).

+21

, API 7, , , :

listFragment.getListView().smoothScrollToPosition(0);
+6

All Articles