So far you have created an Adapter and added a View Holder and also code to onBindViewHolder.
Now it’s time to create a Recycler View which will use this Adapter. It will also pass data to this Adapter.
In order to do this you can create a new Activity, for the purpose of understanding. Let’s call this MaterialActivity. You will call this from the MainActivity on click of a button.
In the layout file for the new Activity you need to add the RecyclerView.
To create a basic Adapter which can be used by the RecyclerView create a new class and extend RecyclerView.Adapter
Once you do this you need to override the following three methods
The getItemCount method is used to return the number of items in the data set.
The onCreateViewHolder method is used to create the views.
The onBindViewHolder method is used to bind views to data.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
Material Design was launched with Android 5.0 (API level 21). The purpose being to provide consistent look and feel to all the Apps. So your App looks consistent with a Google App like Gmail.
It uses Animation and 3D effects.
Android provides the following elements for you to build material design apps:
A new theme – Provides a new style for your App.
New widgets for complex views
New APIs for custom shadows and animations
Two of the most important Material Design widgets are Recycler and Card Views.
RecyclerView widget is a more pluggable version of ListView that supports different layout types and provides performance improvements.
CardView widget lets you display important pieces of information inside cards that have a consistent look and feel.
In addition to the X and Y properties, views in Android now have a Z property. Views with higher Z values cast bigger shadows and appear on top of other views.
To learn more about the principles of Material Design visit the following URL
In the last Article you learnt how to bind MainActivity with BoundService.
Time for you to call the displayDistance method to display the distance traveled. You can create a new method which will return the distance computed. This method will create a Handler and invoke the Service every second.