Adding the map
Now that our application is configured for us to use map services, we can begin discussing how to add a visual map to our application. For the map, we will create another Fragment, which will be loaded on the second page of ViewPager
.
There are two methods to display Google Map; either a MapFragment
or a MapView
object can represent it.
Adding the fragment
Create a new Java class within our fragments
directory with the name MyMapFragment
. The class should extend the Fragment
type. Then, override the OnCreateView
method and let it return the inflated view of fragment_my_map
:
package com.packtpub.masteringandroidapp.fragments; import … /** * Created by Unathi on 7/29/2015. */ public class MyMapFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_my_map, container, false); return view; } }
Next, create the layout file...