Performance of Android ListView containing TextViews

Few minutes ago I radically improved performance of the ListView scrolling in my application. Problem was not so obvious, so I though it might be worth sharing this tip.

Every item in my ListView contains four TextViews. Using Traceview I have found that most of the time was spent in the TextView.setText(CharSequence). In the beginning I though there is nothing I can do here, because the bottleneck was in SDK class and I was already considering some crazy things to do on my side.

Then I realized that in two of these TextView I am most of the times passing strings that are too long to fit there so I tried to truncated them and Bam! The scrolling was silky smooth!

The only thing I had to do was to find the right number of characters to truncate to. It can be done easily by breakText() method:

The result is really significant on both - the real device and the Traceview stats. It's amazing how such discovery can make my day, I mean night. So don't forget, Traceview is your friend.