On this page

Application to display personal details using GUI Components

activity_main.xml file:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/profile_image"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="24dp"
        android:src="@drawable/image_file_name" />
    
    <TextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Name"
        android:textSize="20sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_below="@id/profile_image"
        android:layout_marginTop="24dp"/>
    
    <TextView
        android:id="@+id/age"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Age"
        android:textSize="20sp"
        android:gravity="center"
        android:layout_below="@id/name"
        android:layout_marginTop="8dp"/>
    
    <TextView
        android:id="@+id/email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Email"
        android:textSize="20sp"
        android:gravity="center"
        android:layout_below="@id/age"
        android:layout_marginTop="8dp"/>
    
    <TextView
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Phone"
        android:textSize="20sp"
        android:gravity="center"
        android:layout_below="@id/email"
        android:layout_marginTop="8dp"/>

</RelativeLayout>
1
Copied!

MainActivity.java file:

MainActivity.java
package com.example.myapplication;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    TextView name, age, email, phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        name = findViewById(R.id.name);
        age = findViewById(R.id.age);
        email = findViewById(R.id.email);
        phone = findViewById(R.id.phone);
        
        // Set the values for the TextViews
        name.setText("Mr. X");
        age.setText("20");
        email.setText("x@gmail.com");
        phone.setText("8989898989");
    }
}
1
Copied!