Android, Baseadapter optimization when dealing with large data volumes

Source: Internet
Author: User

Android optimization is the most common is the ListView, Gallery, GridView, Viewpager Big Data optimization picture optimized access network optimization
Optimization principle: Data delay loading local cache in batches
Data optimization 1). Multiplexing Contentview
2). Create a static class Viewholder
3). batch load Slide monitor or button to show more data drag down to display

Picture optimization 1). Asynchronous loading
2). Local cache (level two cache memory (soft reference implementation), SD card)
3). Do not show pictures when sliding quickly
4). Divided into core thread pool and common thread pool, download pictures and other time-consuming tasks placed in the normal thread pool

Asynchronous loading Asyntask Android packaged asynchronous data acquisition, including three methods
Doinbackground executing async methods in a child thread
Onprogressupdate the method that is executed after data acquisition, where the UI interface can be updated in the main thread
OnPostExecute methods that are executed in the main thread before the asynchronous method can be performed with friendly hints
You can also encapsulate a task class (a child thread) thread pool it needs to maintain a task list and prioritize tasks.

Code optimized for adapter:

Java code
    1. Public class Holderadapter<e> extends abstractadapter<e> {
    2. Public Holderadapter (Layoutinflater inflater, viewcreator<e> creator) {
    3. Super (Inflater, creator);
    4. }
    5. private static class viewholder{
    6. Public view view;
    7. }
    8. @Override
    9. Public View GetView (int position, View Convertview, ViewGroup parent) {
    10. //Holder view mode implementation
    11. if (Convertview = = null) {
    12. Viewholder holder = new Viewholder ();
    13. Convertview = Mcreator.createview (Minflater, Position,getitem (position));
    14. Holder.view = Convertview;
    15. Convertview.settag (holder);
    16. } Else {
    17. Viewholder holder = (viewholder) convertview.gettag ();
    18. //Release the current view data
    19. Mcreator.releaseview (Convertview, GetItem (position));
    20. //Update new data to Hodlerview
    21. Mcreator.updateview (Holder.view, Position, GetItem (position));
    22. }
    23. return convertview;
    24. }
    25. }

Android, Baseadapter optimization when dealing with large data volumes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.