public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { System.Diagnostics.Debug.WriteLine(firstVisibleItem); if (firstVisibleItem + visibleItemCount == totalItemCount) // Clear items, add from current half way to chunk size after last item, scroll back to old last item { var firstItem = adapter.GetItem(chunksize); adapter.Clear(); for (int i = 0; i < chunksize * 2; i++) { adapter.Add(firstItem.AddDays(i)); } adapter.NotifyDataSetChanged(); view.SetSelection(chunksize - visibleItemCount - 1); } else if (firstVisibleItem == 0) // Clear items, add from chunk size before first item, scroll back to old first item { var lastItem = adapter.GetItem(chunksize); adapter.Clear(); for (int i = chunksize * 2 - 1; i >= 0; i--) { adapter.Add(lastItem.AddDays(-i)); } adapter.NotifyDataSetChanged(); view.SetSelection(chunksize - 1); } }
/// <summary> /// Bind this class to the goto top button in the parent view /// </summary> /// <param name="parentView"></param> /// <param name="listView"></param> public void BindControl(View parentView, AbsListView listView) { if (parentView != null) { fab = parentView.FindViewById <FloatingActionButton>(Resource.Id.goto_top_button); if (fab != null) { // Hide the button initially fab.Visibility = ViewStates.Gone; // Hook into the listview's scroll events listView.SetOnScrollListener(this); // Scroll back to the top when the button is clicked fab.Click += (sender, e) => { if (listView.FirstVisiblePosition > 20) { listView.SetSelection(20); } listView.SmoothScrollToPosition(0); }; } } else { fab = null; } }