Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Topics Lab 5 Part II

Similar presentations


Presentation on theme: "Android Topics Lab 5 Part II"— Presentation transcript:

1 Android Topics Lab 5 Part II
Build an app containing a Scrollable Contact List Dynamically populate the list with 20 friend (family) contacts

2 App Structure Add the drawable Resources.

3 Build the Layouts friend_layout.xml: contact_item.xml: Scrollable
Contains an internal LinearLayout TIP: Research ScrollView contact_item.xml: LinearLayout

4 friend_layout.xml: The main activity layout. components
ScrollView LinearLayout Root View Internal LinearLayout that will hold a list of contacts.

5 contact_item.xml: The visual display of a contact. components
LinearLayout ImageView LinearLayout TextView TextView

6 Data Model: Contact.java
public String name; public String relationship; public int imageID;

7 Controller: MainActivity.java
Task 1: Instantiate a layout inflater to inflate individual friend contacts (contact_item) Task 2: Create a list of 20 Contact objects. Each Contact object should consist of a name, relationship, and a photo. Task 3: Reference the internal LinearLayout in the main activity. This is where the list of contacts will be displayed. Task 4: Dynamically create a View for each Contact object in the ArrayList and add it to the scrolling internal LinearLayout. Step a) Inflate a contract_item layout. Step b) Reference the ImageView and TextViews in the contact_item. Step c) Add content to the inflated contact_item. Step d) Add the contact_item to the internal LinearLayout.

8 Controller: MainActivity.java
Task 1: Instantiate a layout inflater to inflate individual friend contacts (contact_item) LayoutInflater layoutInflater = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE);

9 Controller: MainActivity.java
Task 2: Create a list of 20 Contact objects. Each Contact object should consist of a name, relationship, and a photo. ArrayList<Contact> contactList = new ArrayList<Contact>(); contactList.add(new Contact("Arthur Weasley", "father", R.drawable.male1)); .

10 Controller: MainActivity.java
Task 3: Reference the internal LinearLayout in the main activity. This is where the list of contacts will be displayed.

11 Controller: MainActivity.java
Task 4: Dynamically create a View for each Contact object in the ArrayList and add it to the scrolling internal LinearLayout. Step a) Inflate a contract_item layout.

12 Controller: MainActivity.java
Task 4: Step b) Reference the ImageView and TextViews in the contact_item. TextView name_text = (TextView) myContactItem.findViewById(R.id.textView1); . Example: Inflated contract_item layout

13 Controller: MainActivity.java
Task 4: Step c) Add content to the inflated contact_item. name_text.setText(contactList.get(i).name); .

14 Controller: MainActivity.java
Task 4: Step d) Add the contact_item to the internal LinearLayout.


Download ppt "Android Topics Lab 5 Part II"

Similar presentations


Ads by Google