[Curs Android] C07 - Liste (IPW 2011)

813 views

Published on

These slides are part of the Android Development Course which I taught to 10 students, while participating in the IP Workshop Summer School 2011.
http://www.scoaladevara.info/2011/?page_id=39

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
813
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
51
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

[Curs Android] C07 - Liste (IPW 2011)

  1. 1. Android Model View Controller, Observer, liste, adaptoare si reciclare Vlad PETRE vlad@vladpetre.com http://twitter.com/vladpetre88 http://facebook.com/vladpetre88 http://www.linkedin.com/in/vladpetre881 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  2. 2. Model View Controller (I) • Architectural Pattern • Separa – Interfata grafica – Programul in sine – Stocarea datelor • Avantaje – Programare pe componente – Usor de intretinut • Dezavantaje – Poate fi lent2 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  3. 3. Model View Controller (II)3 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  4. 4. Model View Controller (III) • Linie continua – asociere directa • Linie intrerupta – asociere indirecta (ex: Observer)4 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  5. 5. Model View Controller (IV)5 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  6. 6. Observer (I)6 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  7. 7. Observer (II) • Design Pattern • Separa – Obiectul observat – Observator • Avantaje – Programare pe componente – Usor de intretinut – Schema generalizata • Dezavantaje – Poate fi lent7 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  8. 8. Observer – Exemplu (I) Abonarea la Gmail8 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  9. 9. Observer – Exemplu (II) Notificarea9 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  10. 10. ListActivity • Activitate specializata pentru o lista • Poate contine si alte componente • ID-ul listei: – android:id=“@android:id/list” • Metode speciale: – onListItemClick(…) – setListAdapter(…)10 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  11. 11. Adaptor11 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  12. 12. ListView • Container vertical • Optimizat pentru miscare • Implicit, avem componente identice pe fiecare rand • Rolul adaptorului: – Genereaza aceste componente • Evenimente: – setOnItemClickListener(…) – setOnItemLongClickListener(…)12 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  13. 13. Adaptor • Poate fi predefinit: – ArrayAdapter • Sau customizat de programator: – Prin implementarea ListAdapter – Extinderea BaseAdapter13 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  14. 14. Varianta statica cu ArrayAdapter (I)14 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  15. 15. Varianta statica cu ArrayAdapter (II)15 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  16. 16. Varianta dinamica cu ArrayAdapter (I)16 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  17. 17. Varianta dinamica cu ArrayAdapter (II)17 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  18. 18. Concluzii implementare cu ArrayAdapter • ListView – Contine o lista – android:id=“@android:id/list” • Elementele listei – android.R.layout.simple_list_item_1 • Static – Putem utiliza String[] • Dinamic – Putem utiliza ArrayList<String>18 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  19. 19. Sa incercam ceva mai complex 19 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  20. 20. Liste cu elemente complexe • Elementele sunt componente de tip container, ce pot contine: – TextView – ImageView –… • Adaptor custom-made – Prin implementarea ListAdapter – Extinderea BaseAapter20 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  21. 21. Extinderea BaseAdapter (I) • public View getView (int position, View convertView, ViewGroup list); • public int getCount (); • public Object getItem(int position) ; • public long getItemId(int position);21 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  22. 22. BaseAdapter (II) Extinderea22 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  23. 23. Extinderea BaseAdapter (III)23 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  24. 24. Extinderea BaseAdapter (IV)24 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  25. 25. BaseAdapter (V) Extinderea25 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  26. 26. BaseAdapter (VI) Extinderea26 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  27. 27. Reciclare • Reutilizarea Obiectelor • Evitarea crearii de obiecte – new is bad for memory! • Utilizam – buffere27 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  28. 28. Optimizare (I)28 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  29. 29. Optimizare (II)29 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  30. 30. Optimizare (III)30 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  31. 31. Tag-uri (pentru View) • public void setTag(Object tag); • public Object getTag();31 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  32. 32. Eficient folosind Tag32 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  33. 33. Referinte • http://pdm.ipworkshop.ro • http://en.wikipedia.org/wiki/Model%E2%80%93view%E2 • http://developer.android.com/guide/tutorials/views/hel33 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea
  34. 34. Întrebări?34 Scoala de Vara IP Workshop 2011 – Calimanesti Valcea

×