I have to check if the RecyclerView
is able to layoutManager.findLastCompletelyVisibleItemPosition()
always returns -1
for me .This is my code. I refer it form Check if RecyclerView is scrollable
private void setAdapterData() {
mChatAdapter = new ChatAdapter(mMessagesList);
mChatMessagesRecyclerView.setAdapter(mChatAdapter);
boolean ss=isRecyclerScrollable();
Log.e("ss",ss+""+mMessagesList.size()+"ll");
}
public boolean isRecyclerScrollable() {
LinearLayoutManager layoutManager = (LinearLayoutManager) mChatMessagesRecyclerView.getLayoutManager();
if (layoutManager == null || mChatAdapter == null) return false;
Log.e("ss",layoutManager.findLastCompletelyVisibleItemPosition() +"ll");
return layoutManager.findLastCompletelyVisibleItemPosition() < mChatAdapter.getItemCount() - 1;
}
My actual code is
private void setAdapterData() {
mChatAdapter = new ChatAdapter(mMessagesList);
mLayoutManager = new LinearLayoutManager(getApplicationContext());
mChatMessagesRecyclerView.setAdapter(mChatAdapter);
if(isRecyclerScrollable())
mLayoutManager.setStackFromEnd(true);
mChatMessagesRecyclerView.setLayoutManager(mLayoutManager);
}
public boolean isRecyclerScrollable() {
RecyclerView.Adapter adapter = mChatMessagesRecyclerView.getAdapter();
if (mLayoutManager == null || adapter == null) return false;
return mLayoutManager.findLastCompletelyVisibleItemPosition() < adapter.getItemCount() - 1;
}
I am actually looking answer for this question
set setStackFromEnd parameter to recycler view based on some condition check
my current working code is
if(mMessagesList.size()>5)
setStackFromEndLayoutManager();
setAdapterData();
private void setStackFromEndLayoutManager() {
mLayoutManager = new LinearLayoutManager(getApplicationContext());
mLayoutManager.setStackFromEnd(true);
mChatMessagesRecyclerView.setLayoutManager(mLayoutManager);
}
i hard coded here mMessagesList.size()>5 ... i have to make it as dynamic..so i looking for answer Check if RecyclerView is scrollable??/