I want to user swipe refresh , so I need to make sure that I'm at the top of the recycleview .This is my code :
LinearLayoutManager mLayoutManager;
recycle = (RecyclerView) findViewById(R.id.recycle);
mLayoutManager = new LinearLayoutManager(this);
recycle.setLayoutManager(mLayoutManager);
recycle.addOnScrollListener(new RecyclerView.OnScrollListener() {
boolean enable = false;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(recycle != null && mLayoutManager.getChildCount() > 0){
boolean firstItemVisible = mLayoutManager.findFirstVisibleItemPosition() == 0;
boolean topOfFirstItemVisible = mLayoutManager.getChildAt(0).getTop() == 0;
Log.v("this",firstItemVisible + " "+topOfFirstItemVisible);
//boolean topOfFirstItemVisible = recycle.getChildAt(0).getTop() == 0;
enable = firstItemVisible && topOfFirstItemVisible;
}
mSwipeRefreshLayout.setEnabled(enable);
}
});
}
as you can see, I'm using a boolean and I want to check if recycleView was at the top , then it enable the swifeLayout .
How can I do so ? this code is not working and when I'm at the top of the recycleView , it doesn't enable the swipeLayout.