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: contact_item.xml: Scrollable Contains an internal LinearLayout TIP: Research ScrollView contact_item.xml: LinearLayout
friend_layout.xml: The main activity layout. components ScrollView LinearLayout Root View Internal LinearLayout that will hold a list of contacts.
contact_item.xml: The visual display of a contact. components LinearLayout ImageView LinearLayout TextView TextView
Data Model: Contact.java public String name; public String relationship; public int imageID;
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.
Controller: MainActivity.java Task 1: Instantiate a layout inflater to inflate individual friend contacts (contact_item) LayoutInflater layoutInflater = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE);
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)); .
Controller: MainActivity.java Task 3: Reference the internal LinearLayout in the main activity. This is where the list of contacts will be displayed.
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.
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
Controller: MainActivity.java Task 4: Step c) Add content to the inflated contact_item. name_text.setText(contactList.get(i).name); .
Controller: MainActivity.java Task 4: Step d) Add the contact_item to the internal LinearLayout.