I have a RecyclerView
which contains messages
item. I want to scroll to the bottom of layout when the user has pressed a button (like chat application). I have tried this piece of code but it does not work.I need this task done after a few millisecond.Because new message add to adapter in the asynchronous call retrofit.
imgSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(edtMessage.getText().length()>0) {
sentUserMessage();
edtMessage.setText("");
//I try this line or next line.None of them doesn't work
linearLayoutManager.scrollToPositionWithOffset(messages.size(),0);
recyclerView.scrollToPosition(messages.size());
}
}
});