Adapter andcache techniqueTrí Phạm – MultiUni - 2012
Adapter and cache technique   • Adapter in Android   • Cache technique in Android
ADAPTER IN ANDROID
Adapter in Android   • Adapter design pattern
Adapter in Android   • Adapter design pattern (con’t)
Adapter in Android   • Adapter design pattern (con’t)
Adapter in Android   • Adapter design pattern (con’t)
Adapter in Android     •   An Adapter object acts as a bridge between an View and the         underlying data for that vie...
Adapter in Android
Adapter in Android   • Android ListView
Adapter in Android   • Android ListView (con’t)     – Naive and dumb way     – The correct way: List13.java     – The fast...
Adapter in Android   • Considering Adapter for the List View     – Each List item in the List View would be calling its   ...
Adapter in Android   • View Holders     – View Holders hold some data that related to an item to       the view.     – Vie...
Adapter in Android   • View Holders (con’t)     – By using the View Holders, the views are saved into a       class variab...
Adapter in Android   • Android ListView
CACHE TECHNIQUE INANDROID
Cache technique in Android     • Basic cache view technique (for       views that have scrolling       behavior)     • Cac...
Adapter in Android   • Basic cache view technique (for     views that have scrolling behavior)     – Demo EfficientListView
Adapter in Android   • Cache data technique     – Why using cache:       • Some operations are high CPU load and         t...
Adapter in Android   • Cache data technique     – Demo ImageDownloader with soft       (memory) cache
Q&A
Upcoming SlideShare
Loading in...5
×

Adapter and cache technique

1,880

Published on

Slide for lesson of Wednesday 23/5/2012. Great appreciation for our lecturers. =)

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,880
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Adapter and cache technique"

  1. 1. Adapter andcache techniqueTrí Phạm – MultiUni - 2012
  2. 2. Adapter and cache technique • Adapter in Android • Cache technique in Android
  3. 3. ADAPTER IN ANDROID
  4. 4. Adapter in Android • Adapter design pattern
  5. 5. Adapter in Android • Adapter design pattern (con’t)
  6. 6. Adapter in Android • Adapter design pattern (con’t)
  7. 7. Adapter in Android • Adapter design pattern (con’t)
  8. 8. Adapter in Android • An Adapter object acts as a bridge between an View and the underlying data for that view. • One side of the adapter is a data structure like a Java object storing data. the other side of the adapter, there is view that the data structure was transformed into. • The Adapter is also responsible for making a View for each item in the data set.
  9. 9. Adapter in Android
  10. 10. Adapter in Android • Android ListView
  11. 11. Adapter in Android • Android ListView (con’t) – Naive and dumb way – The correct way: List13.java – The fast way: List14.java
  12. 12. Adapter in Android • Considering Adapter for the List View – Each List item in the List View would be calling its “getView()” method. – This method would return a view for the List. – But creating a new View for each list item would be complicated, and the UI would be slow down. – Instead of creating new View for each item, Recycler save these view and passes it to the Adapter. – Adapter uses these view sent by the recycler, when it has to produce any new views.
  13. 13. Adapter in Android • View Holders – View Holders hold some data that related to an item to the view. – View Holders minimizes the amount of work, while writing the same piece of code again and again. – These are used while creating the views, where we have to use more than one time. (TextView)findViewById(R.Id.text); (ImageView)findViewById(R.Id.Icon);
  14. 14. Adapter in Android • View Holders (con’t) – By using the View Holders, the views are saved into a class variable and can be called when needed. holder.text = (TextView)findViewById(R.id.text); holder.icon = (ImageView)findViewById(R.id.icon); convertView.setTag(holder); – A tag can hold any kind of object, that can be set on the view.
  15. 15. Adapter in Android • Android ListView
  16. 16. CACHE TECHNIQUE INANDROID
  17. 17. Cache technique in Android • Basic cache view technique (for views that have scrolling behavior) • Cache data technique
  18. 18. Adapter in Android • Basic cache view technique (for views that have scrolling behavior) – Demo EfficientListView
  19. 19. Adapter in Android • Cache data technique – Why using cache: • Some operations are high CPU load and time consuming. E.g.: load images from network… -> Never do something time consuming twice • Mobile applications, especially Android applications needs optimization for smooth UI.
  20. 20. Adapter in Android • Cache data technique – Demo ImageDownloader with soft (memory) cache
  21. 21. Q&A
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×