#pagination and scroll listener in android studio kotlin
Explore tagged Tumblr posts
Link
pagination and scroll listener in android studio kotlin
_______________________________________________ implementation _______________________________________________ /*Variables*/ private var pastVisibleItems: Int = 0 private var apiCall: Boolean = true private val layoutManager: LinearLayoutManager? =LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) private var mPage: Int = 1 /*obersever*/ mHomeViewModel.mHomePropertyList.observe(this, Observer { if (it != null && !it.data.isNullOrEmpty()) { apiCall=true changeUI(true) mList.addAll(it.data) mAdapterHome?.notifyDataSetChanged() } else { apiCall=false if (mList.isNullOrEmpty()) { changeUI(false) } } }) /*your recycerlview*/ rvPropertyDetail.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { pastVisibleItems = layoutManager.findLastCompletelyVisibleItemPosition() Log.e("Tag","initRecyclerView()-->$pastVisibleItems size()-->${mList.size}") if (pastVisibleItems >= mList.size-1) { if (apiCall) { loadData() } } } }) /*scroll bottom to call api*/ private fun loadData() { mPage += 1 mHomeViewModel.getPropertyList(mPage) } _______________________________________________
0 notes
Text
pagination and scroll listener in android studio kotlin
https://ift.tt/2MAnYBx
pagination and scroll listener in android studio kotlin
_______________________________________________ implementation _______________________________________________ /*Variables*/ private var pastVisibleItems: Int = 0 private var apiCall: Boolean = true private val layoutManager: LinearLayoutManager? =LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) private var mPage: Int = 1 /*obersever*/ mHomeViewModel.mHomePropertyList.observe(this, Observer { if (it != null && !it.data.isNullOrEmpty()) { apiCall=true changeUI(true) mList.addAll(it.data) mAdapterHome?.notifyDataSetChanged() } else { apiCall=false if (mList.isNullOrEmpty()) { changeUI(false) } } }) /*your recycerlview*/ rvPropertyDetail.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { pastVisibleItems = layoutManager.findLastCompletelyVisibleItemPosition() Log.e("Tag","initRecyclerView()-->$pastVisibleItems size()-->${mList.size}") if (pastVisibleItems >= mList.size-1) { if (apiCall) { loadData() } } } }) /*scroll bottom to call api*/ private fun loadData() { mPage += 1 mHomeViewModel.getPropertyList(mPage) } _______________________________________________
via Blogger https://ift.tt/2JeRDhv
0 notes