2. Arif Akbarul Huda
Android Developer di qiscus
Penulis buku “Livecoding! 9 Aplikasi Android
Buatan Sendiri”
omayib@gmail.com (email) | @omayib (Twitter)
“jika pelukis memilki kanvas untuk mencurahkan imajinasinya,
Maka programmer punya RAM yang bisa di manipulasi sesuai
imajinasi”
6. How it works?
● ListView asks adapter “give me a view”
(getView) for each item of the list
● A new View is returned and displayed
7. Q : what if we have one billion items? Create new
view for each item?
8. Q : what if we have one billion items? Create new
view for each item?
A : Android caches views for you :)
9. ListView is designed for scalability and
performance. In practice, this essentially means:
● It tries to do as few view inflations as possible.
● It only paints and lays out children that are (or
are about to become) visible on screencode.
http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
10.
11. Add Item Clear
User : add item 1 and dispay it!
ListView : “hey adapter, give me a view..!”
Adapter : “ok, but we don't have”
“i will create a view by inflating selected layout”
“then I will keep this view on my scrapview collection
for use letter”
“wait a seconds..i set your data”
“oke done, there is a view for you”
ListView : “yah! Thanks, render was succedeed”
Item 1
View tag : 001
12. Add Item Clear
User : add item 2 and dispay it!
ListView : “hey adapter, give me a view..!”
Adapter : “ok, but the view I created before still used
for item 1 so we don't have any stock”
“i will create a view by inflating selected layout (again)”
“then I will keep this view on my scrapview collection
for use letter”
“wait a seconds..i set your data”
“oke done, there is a view for you”
ListView : “yah! Thanks, render was succedeed”
Item 1
Item 2
View tag : 001
View tag : 002
13. Add Item Clear
User : add item 11 and dispay it!
ListView : “hey adapter, give me a view..!”
Adapter : “i am sorry, the view will come outer space.
We no need to render it”
But I will keep current data (item 11) to set leter after
user scrolling down”
ListView : “oke noted!”
Item 1
Item 2
...
Item 9
Item 10
Item 11
View tag : 001
View tag : 002
View tag : 009
View tag : 010
14. Add Item Clear
Adapter : “Hei look, user move scrolling up!”
“the view with tag 001 has been released and not
used”
“i will use this view to display current data (item 11)
ListView : “oke rendered!”
Item 2
Item 3
...
Item 10
Item 11
Item 1
View tag : 001
15. Lets try to practice it!
See project on
https://github.com/omayib/ListviewInspection