18
18
19
19
import android .os .Bundle ;
20
20
import android .support .v4 .app .Fragment ;
21
+ import android .util .Log ;
21
22
import android .view .LayoutInflater ;
22
23
import android .view .View ;
23
24
import android .view .ViewGroup ;
24
25
import android .widget .ImageView ;
25
26
26
27
import com .example .android .android_me .R ;
27
- import com .example .android .android_me .data .AndroidImageAssets ;
28
+
29
+ import java .util .List ;
28
30
29
31
public class BodyPartFragment extends Fragment {
30
32
31
- // TODO (1) Create a setter method and class variable to set and store of a list of image resources
33
+ // Tag for logging
34
+ private static final String TAG = "BodyPartFragment" ;
32
35
33
- // TODO (2) Create another setter method and variable to track and set the index of the list item to display
34
- // ex. index = 0 is the first image id in the given list , index 1 is the second, and so on
36
+ // Variables to store a list of image resources and the index of the image that this fragment displays
37
+ private List <Integer > mImageIds ;
38
+ private int mListIndex ;
35
39
36
40
/**
37
41
* Mandatory empty constructor for the fragment manager to instantiate the fragment
@@ -51,14 +55,28 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
51
55
// Get a reference to the ImageView in the fragment layout
52
56
ImageView imageView = (ImageView ) rootView .findViewById (R .id .body_part_image_view );
53
57
54
- // Set the image to the first in our list of head images
55
- imageView .setImageResource (AndroidImageAssets .getHeads ().get (0 ));
56
-
57
- // TODO (3) If a list of image ids exists, set the image resource to the correct item in that list
58
+ // If a list of image ids exists, set the image resource to the correct item in that list
58
59
// Otherwise, create a Log statement that indicates that the list was not found
60
+ if (mImageIds != null ){
61
+ // Set the image resource to the list item at the stored index
62
+ imageView .setImageResource (mImageIds .get (mListIndex ));
63
+ } else {
64
+ Log .v (TAG , "This fragment has a null list of image id's" );
65
+ }
59
66
60
67
// Return the rootView
61
68
return rootView ;
62
69
}
63
70
71
+ // Setter methods for keeping track of the list images this fragment can display and which image
72
+ // in the list is currently being displayed
73
+
74
+ public void setImageIds (List <Integer > imageIds ) {
75
+ mImageIds = imageIds ;
76
+ }
77
+
78
+ public void setListIndex (int index ) {
79
+ mListIndex = index ;
80
+ }
81
+
64
82
}
0 commit comments