diff --git a/app/src/main/java/com/example/android/android_me/ui/AndroidMeActivity.java b/app/src/main/java/com/example/android/android_me/ui/AndroidMeActivity.java
index 7e5d243b0..db6f37c88 100644
--- a/app/src/main/java/com/example/android/android_me/ui/AndroidMeActivity.java
+++ b/app/src/main/java/com/example/android/android_me/ui/AndroidMeActivity.java
@@ -16,6 +16,7 @@
package com.example.android.android_me.ui;
+import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@@ -24,21 +25,20 @@
// This activity will display a custom Android image composed of three body parts: head, body, and legs
public class AndroidMeActivity extends AppCompatActivity {
- // TODO (1) Create a layout file that displays one body part image named fragment_body_part.xml
- // This layout should contain a single ImageView
-
- // TODO (2) Create a new class called BodyPartFragment to display an image of an Android-Me body part
- // In this class, you'll need to implement an empty constructor and the onCreateView method
- // TODO (3) Show the first image in the list of head images
- // Soon, you'll update this image display code to show any image you want
-
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_me);
- // TODO (5) Create a new BodyPartFragment instance and display it using the FragmentManager
+ // Create a new head BodyPartFragment
+ BodyPartFragment headFragment = new BodyPartFragment();
+
+ // Add the fragment to its container using a FragmentManager and a Transaction
+ FragmentManager fragmentManager = getSupportFragmentManager();
+
+ fragmentManager.beginTransaction()
+ .add(R.id.head_container, headFragment)
+ .commit();
}
}
diff --git a/app/src/main/java/com/example/android/android_me/ui/BodyPartFragment.java b/app/src/main/java/com/example/android/android_me/ui/BodyPartFragment.java
new file mode 100644
index 000000000..bc065113c
--- /dev/null
+++ b/app/src/main/java/com/example/android/android_me/ui/BodyPartFragment.java
@@ -0,0 +1,56 @@
+/*
+* Copyright (C) 2017 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.example.android.android_me.ui;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import com.example.android.android_me.R;
+import com.example.android.android_me.data.AndroidImageAssets;
+
+public class BodyPartFragment extends Fragment {
+
+ /**
+ * Mandatory empty constructor for the fragment manager to instantiate the fragment
+ */
+ public BodyPartFragment() {
+ }
+
+ /**
+ * Inflates the fragment layout file and sets the correct resource for the image to display
+ */
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+ // Inflate the Android-Me fragment layout
+ View rootView = inflater.inflate(R.layout.fragment_body_part, container, false);
+
+ // Get a reference to the ImageView in the fragment layout
+ ImageView imageView = (ImageView) rootView.findViewById(R.id.body_part_image_view);
+
+ // Set the image to the first in our list of head images
+ imageView.setImageResource(AndroidImageAssets.getHeads().get(0));
+
+ // Return the rootView
+ return rootView;
+ }
+
+}
diff --git a/app/src/main/res/layout/activity_android_me.xml b/app/src/main/res/layout/activity_android_me.xml
index 71bd30adb..b7af0db2c 100644
--- a/app/src/main/res/layout/activity_android_me.xml
+++ b/app/src/main/res/layout/activity_android_me.xml
@@ -29,8 +29,12 @@
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
-
-
+
+
+
diff --git a/app/src/main/res/layout/fragment_body_part.xml b/app/src/main/res/layout/fragment_body_part.xml
new file mode 100644
index 000000000..1455ea00b
--- /dev/null
+++ b/app/src/main/res/layout/fragment_body_part.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
\ No newline at end of file