-
-
Save sreereddymenon/7d93ebe5c2994737c34f to your computer and use it in GitHub Desktop.
How to scroll Android Listview to the bottom always
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment