Guest User

Untitled

a guest
Apr 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class ExampleFragment : Fragment() {
  2.  
  3. var loading = false
  4.  
  5. override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
  6. return inflater.inflate(R.layout.fragment_example, container, false)
  7. }
  8.  
  9. override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  10. super.onViewCreated(view, savedInstanceState)
  11. val layoutManager = LinearLayoutManager(context)
  12. recyclerView.layoutManager = layoutManager
  13. recyclerView.addOnScrollListener(object: RecyclerView.OnScrollListener() {
  14. override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
  15. super.onScrolled(recyclerView, dx, dy)
  16. val visibleItemCount = layoutManager.childCount
  17. val totalItemCount = layoutManager.itemCount
  18. val firstVisible = layoutManager.findFirstVisibleItemPosition()
  19. if (!loading && (visibleItemCount + firstVisible) >= totalItemCount) {
  20. loading = true
  21. // Call your API to load more items
  22. }
  23. }
  24. })
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment