SlideShare a Scribd company logo
1 of 21
Download to read offline
Adapter and
cache technique
Trí 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 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.
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 way: List14.java
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.
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);
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.
Adapter in Android

   • Android ListView
CACHE TECHNIQUE IN
ANDROID
Cache technique in Android


     • Basic cache view technique (for
       views that have scrolling
       behavior)
     • Cache data technique
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
         time consuming. E.g.: load images from
         network…
       -> Never do something time consuming twice
       • Mobile applications, especially Android
         applications needs optimization for smooth
         UI.
Adapter in Android

   • Cache data technique
     – Demo ImageDownloader with soft
       (memory) cache
Q&A

More Related Content

What's hot

Android Material Design APIs/Tips
Android Material Design APIs/TipsAndroid Material Design APIs/Tips
Android Material Design APIs/TipsKen Yee
 
Material design basics
Material design basicsMaterial design basics
Material design basicsJorge Barroso
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...Akira Hatsune
 

What's hot (6)

Android Material Design APIs/Tips
Android Material Design APIs/TipsAndroid Material Design APIs/Tips
Android Material Design APIs/Tips
 
3. react - native: component
3. react - native: component3. react - native: component
3. react - native: component
 
Material design basics
Material design basicsMaterial design basics
Material design basics
 
HTML Images
HTML Images HTML Images
HTML Images
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
 
Domain model
Domain modelDomain model
Domain model
 

Viewers also liked

Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapterKrazy Koder
 
Android sync adapter
Android sync adapterAndroid sync adapter
Android sync adapterAlex Tumanoff
 
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Nehil Jain
 
Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)Khaled Anaqwa
 
Android development - ListView & Adapter
Android development - ListView & AdapterAndroid development - ListView & Adapter
Android development - ListView & AdapterLope Emano
 

Viewers also liked (6)

Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapter
 
Android sync adapter
Android sync adapterAndroid sync adapter
Android sync adapter
 
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
 
Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)
 
Android development - ListView & Adapter
Android development - ListView & AdapterAndroid development - ListView & Adapter
Android development - ListView & Adapter
 
Android adapters
Android adaptersAndroid adapters
Android adapters
 

Similar to Adapter and cache technique

Android Development
Android DevelopmentAndroid Development
Android Developmentmclougm4
 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDMaterial Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDJordan Open Source Association
 
Android application development for TresmaxAsia
Android application development for TresmaxAsiaAndroid application development for TresmaxAsia
Android application development for TresmaxAsiaMichael Angelo Rivera
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introductionaswapnal
 
Developing for Android-Types of Android Application
Developing for Android-Types of Android ApplicationDeveloping for Android-Types of Android Application
Developing for Android-Types of Android ApplicationNandini Prabhu
 
Android Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and PatternsAndroid Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and PatternsAdham Enaya
 
Shortify for Android
Shortify for AndroidShortify for Android
Shortify for AndroidDhruv Patel
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsLuis Cruz
 
Android layouts course-in-mumbai
Android layouts course-in-mumbaiAndroid layouts course-in-mumbai
Android layouts course-in-mumbaivibrantuser
 
Android layouts course-in-mumbai
Android layouts course-in-mumbaiAndroid layouts course-in-mumbai
Android layouts course-in-mumbaivibrantuser
 
Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)Visug
 
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...Ontico
 
Marrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 Preview
Marrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 PreviewMarrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 Preview
Marrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 PreviewLucas Jellema
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2Vivek Bhusal
 
Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018Hassan Abid
 
Marakana Android User Interface
Marakana Android User InterfaceMarakana Android User Interface
Marakana Android User InterfaceMarko Gargenta
 
行動App開發管理實務 unit1
行動App開發管理實務 unit1行動App開發管理實務 unit1
行動App開發管理實務 unit1Xavier Yin
 

Similar to Adapter and cache technique (20)

Android Development
Android DevelopmentAndroid Development
Android Development
 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDMaterial Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
 
Android application development for TresmaxAsia
Android application development for TresmaxAsiaAndroid application development for TresmaxAsia
Android application development for TresmaxAsia
 
Androidify workshop
Androidify workshopAndroidify workshop
Androidify workshop
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Developing for Android-Types of Android Application
Developing for Android-Types of Android ApplicationDeveloping for Android-Types of Android Application
Developing for Android-Types of Android Application
 
Android Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and PatternsAndroid Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and Patterns
 
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
 
Shortify for Android
Shortify for AndroidShortify for Android
Shortify for Android
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
 
Android layouts course-in-mumbai
Android layouts course-in-mumbaiAndroid layouts course-in-mumbai
Android layouts course-in-mumbai
 
Android layouts course-in-mumbai
Android layouts course-in-mumbaiAndroid layouts course-in-mumbai
Android layouts course-in-mumbai
 
Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)Building your first android app using xamarin (Gill Cleeren)
Building your first android app using xamarin (Gill Cleeren)
 
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
 
Marrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 Preview
Marrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 PreviewMarrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 Preview
Marrying HTML5 and Angular to ADF - Oracle OpenWorld 2014 Preview
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
 
Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018
 
Marakana Android User Interface
Marakana Android User InterfaceMarakana Android User Interface
Marakana Android User Interface
 
行動App開發管理實務 unit1
行動App開發管理實務 unit1行動App開發管理實務 unit1
行動App開發管理實務 unit1
 
Micro frontend
Micro frontendMicro frontend
Micro frontend
 

More from Hoang Vy Nguyen

Android platfom discete_topics
Android platfom discete_topicsAndroid platfom discete_topics
Android platfom discete_topicsHoang Vy Nguyen
 
Android platform broadcast_receiver_intent
Android platform broadcast_receiver_intentAndroid platform broadcast_receiver_intent
Android platform broadcast_receiver_intentHoang Vy Nguyen
 
Android content provider
Android content providerAndroid content provider
Android content providerHoang Vy Nguyen
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgetsHoang Vy Nguyen
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgetsHoang Vy Nguyen
 
Android platform activity
Android platform activityAndroid platform activity
Android platform activityHoang Vy Nguyen
 
Android platform overview
Android platform overviewAndroid platform overview
Android platform overviewHoang Vy Nguyen
 

More from Hoang Vy Nguyen (7)

Android platfom discete_topics
Android platfom discete_topicsAndroid platfom discete_topics
Android platfom discete_topics
 
Android platform broadcast_receiver_intent
Android platform broadcast_receiver_intentAndroid platform broadcast_receiver_intent
Android platform broadcast_receiver_intent
 
Android content provider
Android content providerAndroid content provider
Android content provider
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgets
 
Android platform widgets
Android platform widgetsAndroid platform widgets
Android platform widgets
 
Android platform activity
Android platform activityAndroid platform activity
Android platform activity
 
Android platform overview
Android platform overviewAndroid platform overview
Android platform overview
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Adapter and cache technique

  • 1. Adapter and cache technique Trí Phạm – MultiUni - 2012
  • 2. Adapter and cache technique • Adapter in Android • Cache technique in Android
  • 4. Adapter in Android • Adapter design pattern
  • 5. Adapter in Android • Adapter design pattern (con’t)
  • 6. Adapter in Android • Adapter design pattern (con’t)
  • 7. Adapter in Android • Adapter design pattern (con’t)
  • 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.
  • 10. Adapter in Android • Android ListView
  • 11. Adapter in Android • Android ListView (con’t) – Naive and dumb way – The correct way: List13.java – The fast way: List14.java
  • 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. 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. 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. Adapter in Android • Android ListView
  • 17. Cache technique in Android • Basic cache view technique (for views that have scrolling behavior) • Cache data technique
  • 18. Adapter in Android • Basic cache view technique (for views that have scrolling behavior) – Demo EfficientListView
  • 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. Adapter in Android • Cache data technique – Demo ImageDownloader with soft (memory) cache
  • 21. Q&A