Skip to content

Instantly share code, notes, and snippets.

@creativepsyco
Created July 31, 2013 02:23
Show Gist options
  • Save creativepsyco/6118829 to your computer and use it in GitHub Desktop.
Save creativepsyco/6118829 to your computer and use it in GitHub Desktop.
How to scroll Android Listview to the bottom always
public void scrollBottom() {
// scroll bottom requires posting a runnable to the listView
// in the case of items loading by themselves dynamically
// there may be sync issues and scrolling won't be proper
m_bNeedScrollToBottom = false;
if (m_listView.getLastVisiblePosition()-m_listView.getFirstVisiblePosition() <= m_listView.getCount())
m_listView.setStackFromBottom(false);
else
m_listView.setStackFromBottom(true);
BBUILoop.getInstance().delayPost(new Runnable() {
@Override
public void run() {
int nCount = mItemHostSection.getCount();
BBAppLogger.i("Want Scroll bottom:%d", nCount);
if (nCount > 0 && m_listView != null) {
m_listView.clearFocus();
m_listView.setSelection(m_listView.getAdapter().getCount() - 1);
// This seems to work
m_listView.post(new Runnable() {
@Override
public void run() {
m_listView.setSelection(m_listView.getAdapter().getCount() - 1);
}
});
}
}
}, 400);
}
@chongivan
Copy link

why would you wanna scroll to the bottom?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment