Your SlideShare is downloading. ×
0
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Lecture Slides for List Views [Android ]

2,041

Published on

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,041
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
128
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • position is the clicked element's position in your Adapter (so you can doadapter.getItem(position) ) row id is the id that corresponds to that element, what your Adapter returns in the getItemId()method.
  • Transcript

    • 1. ListView and Adapters Software Development for Portable Devices BITS Pilani Goa Campus Sem I 2011-12
    • 2. CS C314 Software Development For Portable Devices Foundation of :
    • 3. Problem??
      • Performance
      • 10,000 entries in a list!
        • Less than 10% shown but fetched completely
    • 4. Solution??
      • Populate on Demand
        • Google image search
      • Recycle views to reduce object churn
    • 5. Android – ListView
      • Its a view capable of displaying scrollable list of items
      • It only creates views (widget) if needed
      • It recycles views, e.g. if a row is not displayed anymore it will be recycled and only its content will change.
    • 6. The FLOW diagram
    • 7. Adapters
      • extends "BaseAdapter“
      • "ArrayAdapter" can handle data based on Arrays
      • "SimpleCursorAdapter" handle database related data
      • Your own "CustomAdapter"
    • 8. Android - ListActivity
      • If Activity is primarily showing a list you should extend the activity "ListActivity“
      • It simplifies the handling of a "ListView“
      • Set Listadapter in the onCreate(), via the method setListAdapter().
      • Register the click by onListItemClick(ListView l, View v, int position, long id)
      CS C314 Software Development For Portable Devices
    • 9. onListItemClick
      • Parameters
        • l : The ListView where the click happened
        • v : The view that was clicked within the ListView
        • position : The position of the view in the list
        • id : The row id of the item that was clicked
      CS C314 Software Development For Portable Devices
    • 10.   ListActivity with ArrayAdapter and Android standard layout
      • See the code FirstExample
      CS C314 Software Development For Portable Devices
    • 11.   ListActivity with own layout
      • See the code SecondExample
      • Define the layout in xml for each row
      • Define our own arrayAdapter and using Id telling adapter which UI element is the text
      CS C314 Software Development For Portable Devices
    • 12.   ListActivity with flexible layout
      • See the code ThirdExample
      • Override getView().
      • Performance is not optimized.. Think why?
      CS C314 Software Development For Portable Devices
    • 13.   Performance Issues
      • Creating Java objects for each row is time and memory consumption.
      • findViewById() is a expensive operation
      • Android recycles rows (views) which are not displayed anymore.
      CS C314 Software Development For Portable Devices
    • 14.   Optimized Way
      • Using existing rows saves memory and CPU consumption .
      • convertView - The old view to reuse
      • avoid doing findViewById() if not necessary
      • ViewHolder pattern
      • 175% faster then the older procedure
      CS C314 Software Development For Portable Devices
    • 15.   ViewHolder
      • The ViewHolder stores a reference to the required views in a row
      • ViewHolder is then attached to the row via the method setTag()
      • row is recycled we can get the ViewHolder via getTag() method
      • much faster then the repetitive call of findViewById()
      CS C314 Software Development For Portable Devices
    • 16.   Optimized way
      • See the code
      CS C314 Software Development For Portable Devices
    • 17. Your task
      • Your task is to implement the View holder pattern in the Add food class
      CS C314 Software Development For Portable Devices
    • 18.   Interacting rows
      • Your row layout can also contain views which interact with the underlying data model.
      • Example : Checkboxes
      CS C314 Software Development For Portable Devices
    • 19. Try Out
      • LongClickListeners
      • Single Vs Multiple selection
      • Header and Footers
      CS C314 Software Development For Portable Devices
    • 20. References
      • Spinner tutorial : http://developer.android.com/resources/tutorials/views/hello-spinner.html
      • ArrayAdapter: http://developer.android.com/resources/tutorials/views/hello-spinner.html
      CS C314 Software Development For Portable Devices

    ×