Of Rubber Stamps and CheckBoxes: Why your Android ListView is broken
The problem is, people do not quite understand what it means for views to be reused in the context of a ListView. This blog post is intended to explain what that means, and what consequences that has for your list views and your adapters.
The following description comes from the Swing documentation on how JTables are rendered, but it is instructive for this description, and introduces the central metaphor that helps explain what’s going on with the way ListViews are rendered.
Before you go on to the next few tasks, you need to understand how tables draw their cells. You might expect each cell in a table to be a component. However, for performance reasons, Swing tables are implemented differently.
Instead, a single cell renderer is generally used to draw all of the cells that contain the same type of data. You can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell.
Why would the designers implement the rendering this way? Imagine if each row of the table (or list) were a separate object. Each row would hold references to its own UI widgets, e.g. for TextViews (labels), ImageViews (images). If there were N rows and each row takes on average M bytes of memory, you’d have an average memory footprint of N*M bytes. Given that these lists need to be able to display a large number of items, this would be an unacceptable memory footprint. Furthermore, since most of the list would be offscreen, most of the memory would be completely wasted. While it would be simpler to implement, it would bring any Android phone to its virtual knees.
What you do by defining your adapter view in XML is define the raw features that make up your rubber stamp.
(All images were created with the use of Balsamiq, a great tool for mockups).
Leave a Reply Cancel reply
Top Posts
- Three ways of creating dictionaries in Python
- "Error 418 (I'm a teapot)!?" - A cute Easter egg from Google
- Ternary operator in bash
- How to make a solar system: Introduction to affine transformations and Java 2D
- Hello {planet_name}: Creating strings with dynamic content in Python
- Python Gotcha: Word boundaries in regular expressions
- Clear your cache in NetBeans
- Slips vs mistakes - what WordPress gets wrong that Blogger and Tumblr get right
- R - Sorting a data frame by the contents of a column
- TextMate - Introduction to Language Grammars: How to add source code syntax highlighting embedded in HTML
Tags
Categories
- .net (2)
- Android (7)
- Apple (9)
- data (4)
- eclipse (1)
- Gaming (1)
- git (1)
- go (3)
- hibernate (1)
- iPad (3)
- iPhone (6)
- iPod (2)
- Java (48)
- javascript (6)
- LEGO (6)
- link (17)
- mule (3)
- music (1)
- mysql (1)
- NetBeans (15)
- NetBeans Platform (8)
- open source (4)
- photo (6)
- programming (54)
- Python (18)
- quote (9)
- R (3)
- regular (20)
- scala (7)
- svn (1)
- textmate (4)
- UI (32)
- Uncategorized (71)
- unix (13)
- user interface (2)
- video (3)
Google+
Follow on twitter
Search the site
Nick’s tweets
- Here’s an example courtesy of my wife where you cannot even see the full text of the security questions. tmblr.co/ZgBnamYP5QjXWy… 10 months ago
- I started a webcomic at barrelscrapings.com. I hope you enjoy twitter.com/BarrelScraping… 11 months ago
- I made another game – Worm Game! developmentality.wordpress.com/2019/09/19/i-m… 1 year ago
- #PS4share https://t.co/50xrXj6m9Q 2 years ago
- Anyone around that area - I wouldn't miss this twitter.com/scottlava/stat… 2 years ago
Archives
- September 2019 (1)
- March 2018 (1)
- August 2017 (1)
- May 2017 (1)
- March 2015 (2)
- February 2015 (3)
- January 2015 (2)
- December 2014 (1)
- November 2014 (1)
- October 2014 (3)
- September 2014 (6)
- August 2014 (1)
- June 2014 (1)
- May 2014 (2)
- April 2014 (3)
- March 2014 (2)
- February 2014 (4)
- January 2014 (5)
- December 2013 (1)
- October 2013 (2)
- September 2013 (1)
- February 2013 (3)
- December 2012 (1)
- November 2012 (1)
- October 2012 (2)
- September 2012 (1)
- August 2012 (2)
- July 2012 (1)
- June 2012 (1)
- May 2012 (3)
- March 2012 (4)
- February 2012 (2)
- September 2011 (1)
- August 2011 (1)
- July 2011 (1)
- June 2011 (2)
- May 2011 (7)
- April 2011 (6)
- March 2011 (3)
- February 2011 (8)
- January 2011 (11)
- December 2010 (7)
- November 2010 (6)
- October 2010 (8)
- September 2010 (5)
- August 2010 (3)
- July 2010 (8)
- June 2010 (7)
- May 2010 (13)
- April 2010 (10)
- March 2010 (2)
- February 2010 (9)
- January 2010 (5)
- December 2009 (2)
- November 2009 (1)
- October 2009 (5)
- September 2009 (3)
- August 2009 (1)
- July 2009 (1)
- June 2009 (4)
- May 2009 (2)
- April 2009 (3)
- March 2009 (6)
- February 2009 (5)
- January 2009 (4)
You’re right!!..This is a great explanation of reusing views. I’ve been dealing with these until I understood how they work.
I’m gonna write a technical article about it…
Thanks for sharing this…!!!
Hi Fernando –
Thanks for the kind words, and I’m glad the post was useful to you. When you do write your more technical discussion, please let me know and I’ll link to it
Another interactive prototyping tool you might want to check out is Mockuptiger, you can create, share and preview Web and mobile HTML prototypes. The key is that you can create interactive HTML prototypes with navigation which you can view and test in any browser.
Cool thanks for the info.