Listview Scroll to the end of the list after updating the list Listview Scroll to the end of the list after updating the list android android

Listview Scroll to the end of the list after updating the list


Supposing you know when the list data has changed, you can manually tell the list to scroll to the bottom by setting the list selection to the last row. Something like:

private void scrollMyListViewToBottom() {    myListView.post(new Runnable() {        @Override        public void run() {            // Select the last row so it will scroll into view...            myListView.setSelection(myListAdapter.getCount() - 1);        }    });}


You need to use these parameters in your list view:

  • Scrolllv.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

  • Set the head of the list to it bottomlv.setStackFromBottom(true);

You can also set these parameters in XML, eg. like this:

<ListView   ...   android:transcriptMode="alwaysScroll"   android:stackFromBottom="true" />


A combination of TRANSCRIPT_MODE_ALWAYS_SCROLL and setSelection made it work for me

ChatAdapter adapter = new ChatAdapter(this);ListView lv = (ListView) findViewById(R.id.chatList);lv.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);lv.setAdapter(adapter);adapter.registerDataSetObserver(new DataSetObserver() {    @Override    public void onChanged() {        super.onChanged();        lv.setSelection(adapter.getCount() - 1);        }});