I'm trying to make an app with a button called "Map" that will display a city map once pressed. So far I've made an app which contains the Map button and a separate app for my map which uses the Google Developers' tutorial to display a map when the app is opened. I'm having trouble when I try to combine both apps. I'm working on the OnClickListener but I don't know what I should put so that the map would be displayed after pressing the button.
EDIT
Below is my MapFragment class for the map:
public class MapFragment extends FragmentActivity
{
private GoogleMap mMap;
private LatLngBounds ILOILO = new LatLngBounds(new LatLng(10.6, 122.466), new LatLng(10.716, 122.566));
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.map_layout, container, false);
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMyLocationEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ILOILO.getCenter(), 10));
if (mMap == null)
{
Toast.makeText(this, "Google Maps not available",
Toast.LENGTH_LONG).show();
}
return v;
}
}
Here's my XML file for the map:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
map:uiCompass="false"
map:uiTiltGestures="true"
map:uiZoomControls="true"
map:uiZoomGestures="true"
map:uiRotateGestures="true"
map:uiScrollGestures="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Here's for the button located in my MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton mapButton = (ImageButton) findViewById(R.id.mapButton);
mapButton.setOnClickListener(mapListener);
}
private OnClickListener mapListener = new OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent(MainActivity, MapFragment.class);
startActivity(i);
}
};
I've also modified my Manifest since I've been getting "Unable to find explicit activity class (com.example.ipp.MapFragment); have you declared this activity in your AndroidManifest.xml?" error. Below is my manifest.
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="MapFragment" >
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
PROBLEM
When I try to click the "Map" button, it displays my UI instead of displaying the map I've prepared.