I have converted the chat layout from listView to RecyclerView.
Now m facing some problem, When new messages arrive then it not showing automatically, I have to manually scroll to that messages.
Earlier in ListView it working.
I have used set setStackFormEnd in recylerView.
I want feature like whatsapp has like
if new message arrives and you are able to view last message then it will show that messages but
if you scrolling the messages then it doesn't change the position.
layoutManager.setStackFromEnd(true);
messagesView.setLayoutManager(layoutManager);
messagesView.setItemAnimator(new DefaultItemAnimator());
messagesView.addOnScrollListener(mOnScrollListener);
Sample on Create Code Code
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
final Button addButton = (Button) findViewById(R.id.button_is_reverse);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setStackFromEnd(true);
layoutManager.setReverseLayout(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new DividerDecoration(this));
adapter = new SampleAdapter(items);
recyclerView.setAdapter(adapter);
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
items.add("Items" +items.size());
adapter.notifyItemInserted(items.size());
}
});