try { // code that may cause the app to crash } catch (Exception e) { Log.e(TAG, "Exception: " + e.getMessage()); }
if (data == null || data.isEmpty()) { // handle empty data source } else { // set data to RecyclerView adapter mAdapter.setData(data); mAdapter.notifyDataSetChanged(); }
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = layoutManager.getItemCount();
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
if (!isLoading() && !isLastPage()) {
if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount && firstVisibleItemPosition >= 0) {
loadMoreItems();
}
}
} });