In my project,I use a RecyclerView with pulltorefresh and load more data when scroll to bottom.Here is a code fragment.
mData.addAll(data);
mAdapter.notifyDataSetChanged();
LinearLayoutManager layoutManager = (LinearLayoutManager) this.getLayoutManager();
int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = layoutManager.getItemCount();
I find that when the RecyclerView first load data,and all data can't fill the screen height,the lastVisibleItemPosition and the visibleItemCount is wrong.For example,I load 10 items,all item can show in the scrren. the totalItemCount is 10 but the lastVisibleItemPosition is 1 and the totalItemCount is 2.(should be 9 and 10).
But when I refresh the RecyclerView(Reload data by the same code.) or load more data,the findLastVisibleItemPosition is right.
And when the RecyclerView first load data and show in the screen,I check the findLastVisibleItemPosition is right too.
So my question is,is notifyDataSetChanged a aysnc function? if it is,which event can I get the correct findLastVisibleItemPosition?Or is there a better way to get that?
Thanks to read my poor English.