My ListView should automatically scroll to end, when new message received or sent. But when I use Android keyboard to send message from EditText below ListView, ListView resized and new message, which I want to send, appears out of screen and I have to scroll down to see it, even if keyboard disappears and ListView resizes again.
To scroll ListView I use:
listView.postDelayed(new Runnable() {
@Override public void run() { listView.setSelection(listView.getCount()); } }, 100);
but is not working correctly in my case.
Does anyone know why it may occur? Is there a way, which ALWAYS scroll ListView to end?
Thanks, your help is much appreciated!
Try this insead of your code:
listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
(or set it by XML layout).
You can try to add this line of code after you set selection to your list:
listView.smoothScrollToPosition(listView.getCount());
Resulting code should look like this:
listView.postDelayed(new Runnable() {
@Override
public void run() {
listView.setSelection(listView.getCount());
listView.smoothScrollToPosition(listView.getCount());
}
}, 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With