3. Contents
• MVC
• Lists
– Model
– Adaptor
• List Elements
– Simple
– from XML
• ListActvity
• Optimization
– Recycling
– Tags
– Cache
• GridView
3
4. Model View Controller
• Pattern
• Splits
– UI
– Program
– Data storage
• Advantages
– Programing with components
– Easier to maintain
• Disadvantages
– May be slow
4
10. Specific Activities
• ListActivity
– Specially for a list
– May have other components
– List ID
• android:id=“@android:id/list”
• Special functions
– onListItemClick (…)
– setListAdapter (…)
10
13. ListView
• A vertical container
– Similar with ScrollView
– Optimized for movement
• Identical components
– Each row
– Almost true ;)
• Adapter’s role
– Creates these components
• Events
– setOnItemClickListener (…)
– setOnItemLongClickListener (…)
13
14. Adapter
• Part of View
• Specifies the way of
display
– Adapts the data
– Modifies the View
14
20. A simple list
• ListView
– Contains a list
– android:id=“@android:id/list”
• Elements of the list
– android.R.layout.simple_list_item_1
• Static
– May use String[]
• Dynamic
– Use ArrayList<String>
20
21. The List with complex elements
• Elements
– Components
• EditView
• ImageView
• Container
• Adapter custom-made
– Implement ListAdapter
– Extend BaseAdapter
21
22. Extend BaseAdapter
• View getView (int position, View convertView,
ViewGroup list)
• int getCount ()
• Object getItem (int position)
• long getItemId (int position)
• int getViewTypeCount ()
• int getItemViewType (int position)
22
36. The new RecyclerView
• A new way of building lists
– Uses several layouts
• Not just a LinearLayout
– The developer has to use recycling and tagging
• Extend RecyclerView.Adapter
– onCreateViewHolder()
• Inflate the view
– onBindViewHolder()
• Set the View’s data
– getItemCount()
36
37. Conclusions
• Lists
– Linear containers
– Contain components
• Including containers
• ListActivity
– Activity with special functions for list
• Adapter
– Formats the data from the model for the list
– Simple
– Custom made
– Recycling of elements
• Elements
– Described in XML
37