In a normal recyclerview, the newest items are all at the top and if you add an item into the recyclerview, it pushes the existing items down and the new item takes the top posi
I didn't really want to use a SwipeToRefreshLayout at the end as it doens't look good when you have a comment feed.
So what I did was modify the onLoadMoreListener method so that it detects when the actiivity is first started up. If it is first starting up, we do not want the progress bar to be displayed:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
initial = true;
}
}
Then we will use the initial boolean variable to determine whether the activity has just started up and disable the progress bar.
@Override
public void onLoadMore(int current_page) {
//add progress item
if (initial) {
//we do not add the progress bar when the activity opens initially so
//we do nothing. We just change the variable to false so going forward, you will add a progress bar each time you refresh
initial = false;
} else {
comments.add(createProgressBar());
mCommentAdapter.notifyItemInserted(comments.size()-1);
}
Simon: solution I previously proposed here works fine with reverse layout without any modification. The only thing I'd add for reverse layout is to scroll automatically to first item when you show it first time but that's up to you. Now getting back to issue you have. You mentioned that when you scroll nothing happens. so my guess is that you initialize your recylcer view in a wrong order. Make sure you do it like this
mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new MyAdapter<>(myDataset, mRecyclerView);
mRecyclerView.setAdapter(mAdapter);
Note that layout manager gets instantiated first, then you set it and after that you provide adapter. Let me know if that was the case.
Edit Just bringing up this from comment below:
forget about what we have with
onLoadMoreListener
and all scrolling stuff just use standardRecyclerView
wrapped inSwipeToRefreshLayout