diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
new file mode 100644
index 000000000..0450824c1
Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 000000000..15a15b218
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 000000000..7ac24c777
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..7631aec35
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 000000000..fd6b9abf3
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 000000000..7f68460d8
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..94a25f7f4
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/android/android_me/ui/MainActivity.java b/app/src/main/java/com/example/android/android_me/ui/MainActivity.java
index 0a1aa44bb..39ae76e5b 100755
--- a/app/src/main/java/com/example/android/android_me/ui/MainActivity.java
+++ b/app/src/main/java/com/example/android/android_me/ui/MainActivity.java
@@ -18,12 +18,13 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
+import android.widget.Toast;
import com.example.android.android_me.R;
// This activity is responsible for displaying the master list of all images
// TODO (4) Implement the MasterListFragment callback, OnImageClickListener
-public class MainActivity extends AppCompatActivity {
+public class MainActivity extends AppCompatActivity implements MasterListFragment.OnImageClickListener {
@Override
@@ -33,6 +34,12 @@ protected void onCreate(Bundle savedInstanceState) {
}
+ @Override
+ public void onImageSelected(int position) {
+ //Create a toast that displays the position that was clicked
+ Toast.makeText(this, "Position clicked =" + position, Toast.LENGTH_SHORT).show();
+ }
+
// TODO (5) Define the behavior for onImageSelected; create a Toast that displays the position clicked
}
diff --git a/app/src/main/java/com/example/android/android_me/ui/MasterListFragment.java b/app/src/main/java/com/example/android/android_me/ui/MasterListFragment.java
index 0c7e2404c..eb2c82d5d 100755
--- a/app/src/main/java/com/example/android/android_me/ui/MasterListFragment.java
+++ b/app/src/main/java/com/example/android/android_me/ui/MasterListFragment.java
@@ -16,11 +16,13 @@
package com.example.android.android_me.ui;
+import android.content.Context;
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.AdapterView;
import android.widget.GridView;
import com.example.android.android_me.R;
@@ -35,13 +37,36 @@ public class MasterListFragment extends Fragment {
// The callback is a method named onImageSelected(int position) that contains information about
// which position on the grid of images a user has clicked
+
+ OnImageClickListener mCallback;
+
+ public interface OnImageClickListener{
+ void onImageSelected(int position);
+ }
+
// TODO (2) Override onAttach to make sure that the container activity has implemented the callback
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+
+ try {
+ mCallback = (OnImageClickListener) context;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(context.toString() + "must implement OnImageClickListener");
+ }
+ }
+
// Mandatory empty constructor
public MasterListFragment() {
+
}
+
+
+
+
// Inflates the GridView of all AndroidMe images
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -61,6 +86,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// TODO (3) Set a click listener on the gridView and trigger the callback onImageSelected when an item is clicked
+ gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int position, long l) {
+ //Trigger tbe callback method and pass in the position that was clicked
+ mCallback.onImageSelected(position);
+ }
+ });
+
// Return the root view
return rootView;
}