listview and adapter

15
http://android.amberfog.com/?p=296 Join room on qicus bit.ly/androiduii Listview and Adapter

Upload: arif-huda

Post on 30-Jul-2015

446 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Listview and Adapter

http://android.amberfog.com/?p=296

Join room on qicusbit.ly/androiduii

Listview and Adapter

Page 2: Listview and Adapter

Arif Akbarul Huda

Android Developer di qiscusPenulis buku “Livecoding! 9 Aplikasi Android Buatan Sendiri”[email protected] (email) | @omayib (Twitter)

“jika pelukis memilki kanvas untuk mencurahkan imajinasinya,Maka programmer punya RAM yang bisa di manipulasi sesuai

imajinasi”

Page 3: Listview and Adapter

Good reference

● javatpoint.com/java-oops-concepts

● oodesign.com● c4learn.com● Livecoding! 9 Aplikasi Android Buatan Sendiri

Page 4: Listview and Adapter
Page 5: Listview and Adapter

Behind the screen

Page 6: Listview and Adapter

How it works?

● ListView asks adapter “give me a view” (getView) for each item of the list

● A new View is returned and displayed

Page 7: Listview and Adapter

Q : what if we have one billion items? Create new view for each item?

Page 8: Listview and Adapter

Q : what if we have one billion items? Create new view for each item?

A : Android caches views for you :)

Page 9: Listview and Adapter

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/

Page 10: Listview and Adapter
Page 11: Listview and Adapter

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

Page 12: Listview and Adapter

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

Page 13: Listview and Adapter

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

Page 14: Listview and Adapter

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

Page 15: Listview and Adapter

Lets try to practice it!

See project on https://github.com/omayib/ListviewInspection