
Dynamic Contact List Creation in Android App
"Learn how to build an Android app with a scrollable contact list dynamically populated with 20 friend or family contacts. Explore step-by-step instructions on designing layouts, creating a data model, and implementing the controller in Java."
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
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 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. Example: Inflated contract_item layout TextView name_text = (TextView) myContactItem.findViewById(R.id.textView1); . . .
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.