This project will help you practice the skills and concepts you learned related to structs and classes in Java. For this project you'll build an app that is a basic contacts manager app. It will allow you to save and view contact information for your friends.
- Create a new Android Studio project
- Name the project "Friends"
- Open the app's activity_main.xml file.
- Add two edit text fields to the main screen.
- Add a button to the main screen
- Make the button's text "Create Contact"
- Add a scroll view with a linear layout child to the screen.
- Create an even listener for the button in MainActivity.java
- Create data members for all other widgets MainActivity.java
- Create a new file called "Contact.java"
- Create a class called
Contact
- Add
String name
andString phoneNumber
properties. - Write an constructor that takes
name
andphoneNumber
as arguments and initializes the corresponding properties usingthis.
syntax.
- Create a new file called "ContactsManager.java"
- Create a class called
ContactsManager
- It should contain a variable array property called
contacts
whose type is an ArrayList ofContact
objects - Add a method called
Contact createContact(String name, String phoneNumber)
. It should create a new instance ofContact
, and add it to thecontacts
ArrayList. - In
MainActivity.java
, add a data member calledcontactsManager
instantiate and assign an instance ofContactsManager
to it (ContactsManager contactsManager = new ContactsManager()
)
- In the action for the "Create Contact" button, get the strings entered in the text field.
- Use these strings to call the contacts manager's
createContact()
method. - Write a method that will generate and return a
TextView
that accepts aString
as the text value. - Refresh the the text view by adding the new contact as a new text view to your linear layout view.
- Every contact from the array should be in this list
- Build and run your app using the your preferred testing environment.
- Enter various contacts making sure that they text view shows each contact you create.
If you finish and want another challenge try adding the ability to delete contacts.
TIP: You'll have to find a way to identify which contact to delete. The "TAG" attribute allows you to attach hidden information to the UI element. This could be used to add a unique id that would then be matched in the
Contact
class to ensure that the correct contact is deleted.