I remember a couple of years or so ago I was writing something for Android that had a chat component in it(or well…that basically was the main function) and I spent a lot of time trying to get things to work well…I don’t know, like a chat application? I remember googling quite a lot and nothing extremely relevant came up so I ended up wasting a lot of time on trial and error.
About a year or so ago I was working on something that had a chat component again and somehow I was blessed by the Gods of Google and something relevant actually got spit out and I thought maybe I should write it here incase someone else somewhere finds it handy and has hit a wall like I had. So say you have a ListView in your XML:
There’s two things that you’ll generally want from a ListView in a chat application:
1. Items that stack from the bottom of the ListView
2. Some kind of auto-scrolling so new messages can actually be seen by the user.
And there’s two attributes you can use two do this really easily, stackFromBottom and transcriptMode:
stackFromBottom is pretty self explanatory, with this change list items will stack from the bottom of the ListView. transcriptMode is a little less obvious, when set to alwaysScroll it will always scroll to the bottom when new items are added and a call is made to the adapter’s notifyDataSetChanged() method. When set to normal it will only auto-scroll to the newest item/s when the very last list item is still in view. Anyway if your curious have a play around.