You are on page 1of 30

Mobile Application

Development
Lecture 15
Today’s Agenda
• Disadvantages of List View
• Introduction to Recycler View
• Card view
• Recycler View Adapter
Disadvantages of Listview
• List view is plan and simple (Not eye catching)
• List view consist of only one scroll.
• Recycler View:
• Recycler view address these issues.
• It provide more flexibility with appearance.
Recycler View
• Like list view, recycler view also accesses its data using an adapter.
• Unlike a list view, however, it doesn’t use any of the built-in Android
adapters such as array adapters.
• Instead, you have to write an adapter of your own that’s tailored to your
data. This includes specifying the
• Type of data
• Creating views
• And binding the data to the views.
• There are a number of built-in layout managers you can use that allow you
to position items in a linear list or grid.
• Items are positioned in a recycler view using a layout manager.
Here’s what we’re going to do
Add the pizza data
Display the pizza data in a card
• Add the CardView and RecyclerView Support Libraries
How to create a card view
• You create a card view by adding a <CardView> element to a layout.
The full card_captioned_image.xml
code
How our recycler view adapter will
work
Add a recycler view adapter
Define the adapter’s view holder
Tell the adapter what data it should
work with
Implement the getItemCount()
method
Override the onCreateViewHolder()
method
Override onCreateViewHolder()
method
Add the data to the card views
The full code for
CaptionedImagesAdapter.java
Add the RecyclerView to PizzaFragment’s layout
Add fragment_pizza.xml for
PizzzaFragment
A recycler view uses a layout
manager to arrange its views
Specify the layout manager
• Linear layout manager

• Grid layout manager

• Staggered grid layout manager


The full PizzaFragment.java code
What happens when the code runs

You might also like