Reputation: 1
In my android project, I would like to create a Google Map using java code rather than useing xml, how should I do?
Upvotes: 0
Views: 574
Reputation: 23638
You can add a Map
using MapFragment
to an Activity
in code. To do this, create a new MapFragment
instance, and then call FragmentTransaction.add()
to add the Fragment
to the current Activity
.
mMapFragment = MapFragment.newInstance(); FragmentTransaction fragmentTransaction =getFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.my_container, mMapFragment); fragmentTransaction.commit();
For more details check out the GoogleMaps, you will have more idea of implementing the maps.
Upvotes: 2