Android Topics Lab 5 Part II Build an

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

App Structure Add the drawable Resources.

Build the Layouts • friend_layout. xml: • Scrollable • Contains an internal Linear. Layout • TIP: Research Scroll. View • contact_item. xml: • Linear. Layout

friend_layout. xml: The main activity layout. components Scroll. View Linear. Layout Root View Internal Linear. Layout that will hold a list of contacts.

contact_item. xml: The visual display of a contact. components Linear. Layout Image. View Linear. Layout Text. View

Data Model: Contact. java public String name; public String relationship; public int image. ID;

Controller: Main. Activity. 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 Linear. Layout 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 Array. List and add it to the scrolling internal Linear. Layout. Step a) Inflate a contract_item layout. Step b) Reference the Image. View and Text. Views in the contact_item. Step c) Add content to the inflated contact_item. Step d) Add the contact_item to the internal Linear. Layout.

Controller: Main. Activity. java Task 1: Instantiate a layout inflater to inflate individual friend contacts (contact_item) Layout. Inflater layout. Inflater = (Layout. Inflater) get. System. Service (Context. LAYOUT_INFLATER_SERVICE);

Controller: Main. Activity. java Task 2: Create a list of 20 Contact objects. Each Contact object should consist of a name, relationship, and a photo. Array. List<Contact> contact. List = new Array. List<Contact>(); contact. List. add(new Contact("Arthur Weasley", "father", R. drawable. male 1)); . . .

Controller: Main. Activity. java Task 3: Reference the internal Linear. Layout in the main activity. This is where the list of contacts will be displayed.

Controller: Main. Activity. java Task 4: Dynamically create a View for each Contact object in the Array. List and add it to the scrolling internal Linear. Layout. Step a) Inflate a contract_item layout.

Controller: Main. Activity. java Task 4: Step b) Reference the Image. View and Text. Views in the contact_item. Example: Inflated contract_item layout Text. View name_text = (Text. View) my. Contact. Item. find. View. By. Id(R. id. text. View 1); . . .

Controller: Main. Activity. java Task 4: Step c) Add content to the inflated contact_item. name_text. set. Text(contact. List. get(i). name); . .

Controller: Main. Activity. java Task 4: Step d) Add the contact_item to the internal Linear. Layout.
- Slides: 14