Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

TFragments.04-Solution-CreateMasterListFragment #29

Open
wants to merge 1 commit into
base: TFragments.04-Exercise-CreateMasterListFragment
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<!-- TODO (5) Declare the MainActivity in the manifest and set it to launch upon opening this app -->

<activity android:name=".ui.AndroidMeActivity">
<!-- Declare the MainActivity in the manifest and set it to launch upon opening this app -->
<activity android:name=".ui.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".ui.AndroidMeActivity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@
// 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 fragment_master_list.xml layout file to display all our images; this should be a GridView

// TODO (2) Create a new class called MasterListFragment which will display the GridView list of ALL AndroidMe images
// In the fragment class, you'll need to implement an empty constructor, and onCreateView

// TODO (3) In the MasterListFragment class, create a new MasterListAdapter and set it on the GridView
// The MasterListAdapter code is provided; it creates the ImageViews that are contained in the GridView
// The adapter takes as parameters (Context context, List<Integer> imageIds)

// After creating the fragment..
// TODO (4) Create a new Activity named MainActivity and a corresponding layout file that displays a MasterListFragment
// Remember, to display a static fragment in a layout file, use the <fragment> tag


@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.v7.app.AppCompatActivity;

import com.example.android.android_me.R;

// This activity is responsible for displaying the master list of all images
public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.GridView;

import com.example.android.android_me.R;
import com.example.android.android_me.data.AndroidImageAssets;


// This fragment displays all of the AndroidMe images in one large list
// The list appears as a grid of images
public class MasterListFragment extends Fragment {

// Mandatory empty constructor
public MasterListFragment() {
}

// Inflates the GridView of all AndroidMe images
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

final View rootView = inflater.inflate(R.layout.fragment_master_list, container, false);

// Get a reference to the GridView in the fragment_master_list xml layout file
GridView gridView = (GridView) rootView.findViewById(R.id.images_grid_view);

// Create the adapter
// This adapter takes in the context and an ArrayList of ALL the image resources to display
MasterListAdapter mAdapter = new MasterListAdapter(getContext(), AndroidImageAssets.getAll());

// Set the adapter on the GridView
gridView.setAdapter(mAdapter);

// Return the root view
return rootView;
}

}
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--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.-->

<!-- Display the static master list fragment -->
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/master_list_fragment"
android:name="com.example.android.android_me.ui.MasterListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
27 changes: 27 additions & 0 deletions app/src/main/res/layout/fragment_master_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--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.-->

<!-- GridView that displays AndroidMe images -->
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/images_grid_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:columnWidth="180dp"
android:gravity="center"
android:horizontalSpacing="8dp"
android:numColumns="3"
android:padding="16dp"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp">
</GridView>