I know that this has been answered and you took the answer and it was more than a year ago. But a better way to do this is Transcript Mode. For a demo, see the Android API Demo under Views > Lists > Transcript.
You would set the following on your list view in the XML.
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
It will always work whenever you call notifyDataSetChanged()
. You can set android:transcriptMode
to normal
instead if you want an even better result for chat applications: it will scroll to the bottom only if the last item was already in view. That way your users can view the previous chat without interruption when other users chat.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…