Skip to content

Commit

Permalink
Week 6 Exercise 2b: Fragments defined in layout xmls must not be nested!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary-Anne Cosgrove committed May 3, 2014
1 parent d5976f1 commit 597f5f7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion AndroidBootcamp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
buildToolsVersion '19.0.3'

defaultConfig {
minSdkVersion 14
minSdkVersion 17
targetSdkVersion 19
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testMap() throws InterruptedException {

When.iOpenTheMenuAndSelectItem("Map");

onView(withId(R.id.map)).check(matches(withEffectiveVisibility(VISIBLE)));
onView(withId(R.id.map_container)).check(matches(withEffectiveVisibility(VISIBLE)));
}


Expand Down
3 changes: 0 additions & 3 deletions AndroidBootcamp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@


import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.MapFragment;

import com.thoughtworks.androidbootcamp.R;


public class TreasureMapFragment extends Fragment {

private MapFragment mMapFragment;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_map, container, false);
View mView = inflater.inflate(R.layout.fragment_map, container, false);
addMapFragment();

return mView;
}

private void addMapFragment() {
mMapFragment = MapFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.map_container, mMapFragment)
.commit();
}

}
8 changes: 1 addition & 7 deletions AndroidBootcamp/src/main/res/layout/fragment_map.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.thoughtworks.androidbootcamp.controller.fragment.TreasureMapFragment">

<fragment xmlns:android="https://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="Map showing location of attempts"
android:tag="The Map"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,6 @@ Check Android Support Repository, Google Play Services and Google Repository fro
### Resources
[Installing and Configuring the Google Maps V2 API](https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api)
[Google Maps API](https://developer.android.com/google/play-services/maps.html)
[Nested fragments must be added programmatically](https://developer.android.com/about/versions/android-4.2.html#NestedFragments)
[Maps in the Genymotion emulator](https://www.webupd8.org/2013/11/android-x86-emulator-genymotion-20.html)

0 comments on commit 597f5f7

Please sign in to comment.