In this article, we will learn how to develop an Edit Profile Activity in Android Studio in both Kotlin and Java. We will design an Edit Profile form based on Google Material Design components. At the end of this tutorial, the following screen will be designed.
Below we are going to create a simple Activity for Edit Profile. It contains the input fields and a button. If the field is empty then an error message will appear against that field by clicking on the button.

If all data insert correctly then a Toast message will appear “Profile Updated Successfully” as you can see in the following image

Create EditProfile Activity in Your Project
Now you have to create a new Empty Activity with the name of Edit Profile in your Android Studio.
EditProfile Activity XML Code
Copy and Paste the following code in your EditProfileActivity.xml
file.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#FFFFFF"
tools:context=".EditProfileActivity">
<TextView
android:id="@+id/tv_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update Profile Information"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#000"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="24dp"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tv_heading"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_image"
android:layout_width="0dp"
app:layout_constraintWidth_percent="0.7"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="20dp"
android:textColorHint="#808080"
app:layout_constraintTop_toTopOf="parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="165dp"
android:src="@drawable/jd_23_512" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_first_name"
android:layout_width="0dp"
app:layout_constraintWidth_percent="0.7"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="14dp"
android:textColorHint="#808080"
app:layout_constraintTop_toBottomOf="@+id/layout_image"
>
<EditText
android:id="@+id/et_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:gravity="center"
android:padding="30dp"
android:textColor="#000000"
android:textColorHint="#808080"
android:background="#00000000"
android:textSize="15sp"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_last_name"
android:layout_width="0dp"
app:layout_constraintWidth_percent="0.7"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="14dp"
android:textColorHint="#808080"
app:layout_constraintTop_toBottomOf="@+id/layout_first_name"
>
<EditText
android:id="@+id/et_last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name"
android:gravity="center"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#808080"
android:background="#00000000"
android:textSize="15sp"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_email"
android:layout_width="0dp"
app:layout_constraintWidth_percent="0.7"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="14dp"
android:textColorHint="#808080"
app:layout_constraintTop_toBottomOf="@+id/layout_last_name"
>
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:gravity="center"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#808080"
android:background="#00000000"
android:textSize="15sp"
android:inputType="textEmailAddress"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_contact_no"
android:layout_width="0dp"
app:layout_constraintWidth_percent="0.7"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="14dp"
android:textColorHint="#808080"
app:layout_constraintTop_toBottomOf="@+id/layout_email"
>
<EditText
android:id="@+id/et_contact_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Contact No"
android:gravity="center"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#808080"
android:background="#00000000"
android:textSize="15sp"
android:inputType="phone"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_des"
android:layout_width="0dp"
app:layout_constraintWidth_percent="0.7"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="14dp"
android:textColorHint="#808080"
app:layout_constraintTop_toBottomOf="@+id/layout_contact_no"
>
<EditText
android:id="@+id/et_des"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Designation"
android:gravity="center"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#808080"
android:background="#00000000"
android:textSize="15sp"
android:inputType="text"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/bt_register"
android:layout_width="0dp"
android:layout_height="50dp"
app:layout_constraintTop_toBottomOf="@+id/layout_des"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Update Profile"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:background="@color/design_default_color_primary"
android:textAllCaps="false"
android:layout_marginTop="30dp"
app:layout_constraintWidth_percent="0.7"
style="?android:attr/borderlessButtonStyle"
android:elevation="2dp"
android:onClick="performEditProfile"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
EditProfile Activity Kotlin Code
If you are developing your project in Kotlin then you can add the following code in your EditProfileActivity.kt
file.
package com.example.handyopinion
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Patterns
import android.view.View
import android.widget.EditText
import android.widget.Toast
class EditProfileActivity : AppCompatActivity() {
lateinit var etFirstName: EditText
lateinit var etLastName:EditText
lateinit var etEmail: EditText
lateinit var etContactNo:EditText
lateinit var etDes:EditText
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_edit_profile)
viewInitializations()
}
fun viewInitializations() {
etFirstName = findViewById(R.id.et_first_name)
etLastName = findViewById(R.id.et_last_name)
etEmail = findViewById(R.id.et_email)
etContactNo = findViewById(R.id.et_contact_no)
etDes = findViewById(R.id.et_des)
// To show back button in actionbar
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
// Checking if the input in form is valid
fun validateInput(): Boolean {
if (etFirstName.text.toString().equals("")) {
etFirstName.setError("Please Enter First Name")
return false
}
if (etLastName.text.toString().equals("")) {
etLastName.setError("Please Enter Last Name")
return false
}
if (etEmail.text.toString().equals("")) {
etEmail.setError("Please Enter Email")
return false
}
if (etContactNo.text.toString().equals("")) {
etContactNo.setError("Please Enter Contact No")
return false
}
if (etDes.text.toString().equals("")) {
etDes.setError("Please Enter Designation")
return false
}
// checking the proper email format
if (!isEmailValid(etEmail.text.toString())) {
etEmail.setError("Please Enter Valid Email")
return false
}
return true
}
fun isEmailValid(email: String): Boolean {
return Patterns.EMAIL_ADDRESS.matcher(email).matches()
}
// Hook Click Event
fun performEditProfile (view: View) {
if (validateInput()) {
// Input is valid, here send data to your server
val firstName = etFirstName.text.toString()
val lastName = etLastName.text.toString()
val email = etEmail.text.toString()
val contactNo = etContactNo.text.toString()
val etDes = etDes.text.toString()
Toast.makeText(this,"Profile Update Successfully",Toast.LENGTH_SHORT).show()
// Here you can call you API
}
}
}
EditProfile Activity Java Code
If you are developing your Project in Java then you can add the following code in your ResetPasswordActivity.java
file.
package com.example.handyopinion;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class EditProfileActivity extends AppCompatActivity {
EditText etFirstName, etLastName, etEmail, etContactNo, etDec;
final int MIN_PASSWORD_LENGTH = 6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_profile);
viewInitializations();
}
void viewInitializations() {
etFirstName = findViewById(R.id.et_first_name);
etLastName = findViewById(R.id.et_last_name);
etEmail = findViewById(R.id.et_email);
etContactNo = findViewById(R.id.et_contact_no);
etDec = findViewById(R.id.et_des);
// To show back button in actionbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
// Checking if the input in form is valid
boolean validateInput() {
if (etFirstName.getText().toString().equals("")) {
etFirstName.setError("Please Enter First Name");
return false;
}
if (etLastName.getText().toString().equals("")) {
etLastName.setError("Please Enter Last Name");
return false;
}
if (etEmail.getText().toString().equals("")) {
etEmail.setError("Please Enter Email");
return false;
}
if (etContactNo.getText().toString().equals("")) {
etContactNo.setError("Please Enter Contact No");
return false;
}
if (etDec.getText().toString().equals("")) {
etDec.setError("Please Enter Designation ");
return false;
}
// checking the proper email format
if (!isEmailValid(etEmail.getText().toString())) {
etEmail.setError("Please Enter Valid Email");
return false;
}
return true;
}
boolean isEmailValid(String email) {
return Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
// Hook Click Event
public void performEditProfile (View v) {
if (validateInput()) {
// Input is valid, here send data to your server
String firstName = etFirstName.getText().toString();
String lastName = etLastName.getText().toString();
String email = etEmail.getText().toString();
String contactNo = etContactNo.getText().toString();
String Designation = etDec.getText().toString();
Toast.makeText(this,"Profile Update Successfully",Toast.LENGTH_SHORT).show();
// Here you can call you API
}
}
}
This code is Android side code related to the User Interface. We are not calling any API on the server to post the data.
That’s it. This is how to develop an Edit Profile Activity in the Android Studio.
If you have any questions or suggestions, feel free to ask in the comments section below. Thanks