歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發教程:OnScrollListener實現ListActivity滾屏首字母提示

Android開發教程:OnScrollListener實現ListActivity滾屏首字母提示

日期:2017/3/1 10:30:29   编辑:Linux編程

OnScrollListener接口是定義在AbsListView中的,而AbsListView的直接子類有GridView和ListView,非直接子類有ExpandableListView。OnScrollListener的完整路徑是frameworks\base\core\java\Android\widget\AbsListView.java,代碼如下:

[java]
  1. /**
  2. * Interface definition for a callback to be invoked when the list or grid
  3. * has been scrolled.
  4. */
  5. public interface OnScrollListener {
  6. /**
  7. * The view is not scrolling. Note navigating the list using the trackball counts as
  8. * being in the idle state since these transitions are not animated.
  9. */
  10. public static int SCROLL_STATE_IDLE = 0;
  11. /**
  12. * The user is scrolling using touch, and their finger is still on the screen
  13. */
  14. public static int SCROLL_STATE_TOUCH_SCROLL = 1;
  15. /**
  16. * The user had previously been scrolling using touch and had performed a fling. The
  17. * animation is now coasting to a stop
  18. */
  19. public static int SCROLL_STATE_FLING = 2;
  20. /**
  21. * Callback method to be invoked while the list view or grid view is being scrolled. If the
  22. * view is being scrolled, this method will be called before the next frame of the scroll is
  23. * rendered. In particular, it will be called before any calls to
  24. * {@link Adapter#getView(int, View, ViewGroup)}.
  25. *
  26. * @param view The view whose scroll state is being reported
  27. *
  28. * @param scrollState The current scroll state. One of {@link #SCROLL_STATE_IDLE},
  29. * {@link #SCROLL_STATE_TOUCH_SCROLL} or {@link #SCROLL_STATE_IDLE}.
  30. */
  31. public void onScrollStateChanged(AbsListView view, int scrollState);
  32. /**
  33. * Callback method to be invoked when the list or grid has been scrolled. This will be
  34. * called after the scroll has completed
  35. * @param view The view whose scroll state is being reported
  36. * @param firstVisibleItem the index of the first visible cell (ignore if
  37. * visibleItemCount == 0)
  38. * @param visibleItemCount the number of visible cells
  39. * @param totalItemCount the number of items in the list adaptor
  40. */
  41. public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
  42. int totalItemCount);
  43. }
Copyright © Linux教程網 All Rights Reserved