How to Create Contacts App in Android Studio?


A Contacts app in Android Studio is an application that empowers clients to oversee and organise their contact data in a helpful and user-friendly way. It gives a stage for making, putting away, and getting to contact points of interest such as names, phone numbers, mail addresses, and more. Clients can include unused contacts, see existing ones, rummage around for particular contacts, and perform operations like altering or erasing contact data. The app ordinarily utilises highlights like RecyclerView to show contacts in a list arrangement, ProgressBar to demonstrate stacking status, and FloatingActionButton for including modern contacts. By advertising basic functionalities and a well-designed interface, a Contacts app rearranges the method of overseeing contacts and upgrades communication effectiveness on Android gadgets.

Methods Used

  • Manual implementation

Manual Implementation

To form a circular dialogue in Android, you'll be able to physically execute it by following these steps. To begin with, make a custom format for the discourse that incorporates a circular advance bar and any extra components you need. At that point, make a custom Exchange course that amplifies Exchange and set the custom layout using setContentView(). Following, initialise and design the circular advance bar within the custom Exchange lesson. At last, the discourse will appear when required by calling dialogue.show(). This manual execution permits you to have total control over the appearance and behaviour of the circular dialogue, counting customizations such as including content or buttons.

Algorithm

  • Begin the application.

  • Initialise the essential factors and information structures for the app, such as a list to store contacts.

  • Set up the client interface with XML-format records, a recycler view to show the contacts, a progress bar for stacking criticism, and a floating action button for including modern contacts.

  • Create a Contact course to speak to the contact information, counting properties like title, phone number, and email.

  • Implement a connector lesson to tie the contact information to the RecyclerView, taking care of the creation and overhauling of views for each contact item.

  • Set up database usefulness utilising SQLite or other capacity alternatives to store and recover contact information.

  • Load the starting information from the database and populate the recycler view with the contacts.

  • Implement usefulness to include modern contacts utilising the floating action button and upgrade the recycler view accordingly.

  • Implement usefulness to erase or alter contacts by reacting to the client's intuitive interaction with the contact things within the RecyclerView.

  • Implement usefulness to allow clients to hunt for particular contacts by title or other criteria.

  • Test the app on an emulator or physical gadget to guarantee its capacities accurately, taking care of edge cases and client inputs effectively.

  • Handle any potential mistakes or exemptions nimbly to guarantee a smooth client experience.

  • Optimise the app for execution and memory utilisation, considering components like apathetic stacking of information and proficient database operations.

  • Add vital consents and ask for them at runtime, such as read/write contact authorizations for information access.

  • Finalise the app, perform intensive testing, and make any vital alterations based on client criticism or bug reports.

  • Release the app on the Google Play Store or other stages if desired.

Example

Xml Program

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:orientation="vertical"
	tools:context=".MainActivity">

	<!-- RecyclerView for displaying the list of contacts -->
	<androidx.recyclerview.widget.RecyclerView
		android:id="@+id/idRVContacts"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />

	<!-- Progress bar for displaying loading feedback -->
	<ProgressBar
		android:id="@+id/idPBLoading"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_centerInParent="true" />

	<!-- FloatingActionButton for adding a new contact -->
	<com.google.android.material.floatingactionbutton.FloatingActionButton
		android:id="@+id/idFABadd"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_alignParentEnd="true"
		android:layout_alignParentBottom="true"
		android:layout_margin="20dp"
		android:src="@drawable/ic_account"
		app:fabCustomSize="40dp"
		app:tint="@color/white" />

</RelativeLayout>

Xml Program

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/idRLContact"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:layout_margin="3dp">
	
	<!--image view for displaying the first letter of contact-->
	<ImageView
		android:id="@+id/idIVContact"
		android:layout_width="60dp"
		android:layout_height="60dp"
		android:layout_margin="8dp"
		android:padding="3dp"
		android:src="@mipmap/ic_launcher" />

	<!--text view for displaying user name-->
	<TextView
		android:id="@+id/idTVContactName"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_centerVertical="true"
		android:layout_marginStart="8dp"
		android:layout_marginTop="12dp"
		android:layout_marginEnd="8dp"
		android:layout_toRightOf="@id/idIVContact"
		android:text="Contact Name"
		android:textColor="@color/black" />

</RelativeLayout>

Java Program

public class ContactsModal {
	
	// variables for our user name
	// and contact number.
	private String userName;
	private String contactNumber;

	// constructor
	public ContactsModal(String userName, String contactNumber) {
		this.userName = userName;
		this.contactNumber = contactNumber;
	}

	// on below line we have
	// created getter and setter
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getContactNumber() {
		return contactNumber;
	}

	public void setContactNumber(String contactNumber) {
		this.contactNumber = contactNumber;
	}

}

Xml Program

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:app="http://schemas.android.com/apk/res-auto"
	xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	tools:context=".ContactDetailActivity">

	<!--image view for contact-->
	<ImageView
		android:id="@+id/idIVContact"
		android:layout_width="match_parent"
		android:layout_height="300dp"
		android:background="@color/purple_200"
		android:padding="50dp"
		android:src="@drawable/ic_account"
		app:tint="@color/white" />

	<!--text view for displaying user name-->
	<TextView
		android:id="@+id/idTVName"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_below="@id/idIVContact"
		android:background="@color/purple_200"
		android:padding="8dp"
		android:text="Name"
		android:textColor="@color/white"
		android:textSize="18sp" />

	<!--cardview for displaying user contact-->
	<androidx.cardview.widget.CardView
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_below="@id/idTVName"
		android:layout_marginStart="4dp"
		android:layout_marginTop="20dp"
		android:layout_marginEnd="4dp"
		app:cardCornerRadius="4dp"
		app:cardElevation="4dp">

		<RelativeLayout
			android:layout_width="match_parent"
			android:layout_height="wrap_content">
			
			<!--image view for making a call -->
			<ImageView
				android:id="@+id/idIVCall"
				android:layout_width="40dp"
				android:layout_height="40dp"
				android:layout_margin="8dp"
				android:padding="4dp"
				android:src="@drawable/ic_account"
				app:tint="@color/purple_700" />
			
			<!--text view for displaying user contact-->
			<TextView
				android:id="@+id/idTVPhone"
				android:layout_width="match_parent"
				android:layout_height="wrap_content"
				android:layout_centerVertical="true"
				android:layout_marginStart="3dp"
				android:layout_marginTop="8dp"
				android:layout_toStartOf="@id/idIVMessage"
				android:layout_toEndOf="@id/idIVCall"
				android:layout_toRightOf="@id/idIVCall"
				android:text="Phone" />

			<!--image view for displaying message icon-->
			<ImageView
				android:id="@+id/idIVMessage"
				android:layout_width="40dp"
				android:layout_height="40dp"
				android:layout_alignParentEnd="true"
				android:layout_margin="8dp"
				android:padding="4dp"
				android:src="@drawable/ic_account"
				app:tint="@color/purple_700" />

		</RelativeLayout>
	</androidx.cardview.widget.CardView>
</RelativeLayout>

Xml Program

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:orientation="vertical"
	tools:context=".CreateNewContactActivity">

	<!--edit text for user name-->
	<EditText
		android:id="@+id/idEdtName"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_margin="8dp"
		android:hint="Enter Name"
		android:inputType="text" />

	<!--edit text for user phone number-->
	<EditText
		android:id="@+id/idEdtPhoneNumber"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_margin="8dp"
		android:hint="Enter Number"
		android:inputType="phone" />

	<!--edit text for user email-->
	<EditText
		android:id="@+id/idEdtEmail"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_margin="8dp"
		android:hint="Enter Email Address"
		android:inputType="text" />

	<!--button for saving a new contact-->
	<Button
		android:id="@+id/idBtnAddContact"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_margin="10dp"
		android:text="Save Contact"
		android:textAllCaps="false" />

</LinearLayout>

Output

Conclusion

This article gives a comprehensive guide to making a Contacts app in Android Studio. It clarifies that a Contacts app permits clients to oversee and organise their contact data. The article talks about the highlights and functionalities regularly found in a Contacts app, such as including, seeing, looking at, altering, and erasing contacts. It moreover traces the steps included in making the app, counting setting up the client interface, actualizing the fundamental classes and strategies, joining a database for information capacity, and taking care of client intelligence. The article emphasises the significance of testing, optimising execution, and discharging the app to the Google Play Store.

Updated on: 31-Jul-2023

596 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements