Posts

FIREBASE REAL-TIME DATABASE || SAVE, RETRIEVE, LOAD, DELETE DATABASE OF USER DATA || ANDROID STUDIO KOTLIN || DISPLAY IN TABLE LAYOUT


In this post, we will learn how to use firebase's real-time database for saving and retrieving user data online. Let's start


Step 1:  Create a New android studio project with an empty activity.


Step 2: Add firebase to your android studio project and connect to the app.


Step 3: Add firebase real-time database to the app. and setup rules true


Step 4: Add resource images for the user interface like Facebook, Google, and Twitter, and also create vectors in drawable for name, email, phone, and password watch the video for a full guide


Step 5: Add the missing dependencies in the build.Gradle (module app)



dependencies {

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth:21.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.google.firebase:firebase-database:20.1.0'
implementation platform('com.google.firebase:firebase-bom:31.2.3')
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx:24.4.4'
implementation 'com.google.firebase:firebase-database-ktx:20.1.0'

}




Step 6: Add the missing dependencies in the build.Gradle (module project)



buildscript {

dependencies {

classpath 'com.google.gms:google-services:4.3.15'
}
}


plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
}







Step 7: Create two new empty activities with the name LoginActivity and RegisterActivity. then shift the intent filter to register activity in a manifest file and do android:exported="true" > .


Step 8: Now add the following codes to respected activities 



LoginActivity.kt


import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.google.firebase.FirebaseApp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase

class LoginActivity : Activity() {

private lateinit var auth: FirebaseAuth

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// FirebaseApp.initializeApp(this)
setContentView(R.layout.activity_login)

// Initialize Firebase Auth
auth = Firebase.auth





super.onStart()
// Check if user is signed in (non-null) and update UI accordingly.
val currentUser = auth.currentUser
if(currentUser != null){
Toast.makeText(baseContext, "welcome back ",
Toast.LENGTH_SHORT).show()

val intent = Intent(this, MainActivity::class.java)
startActivity(intent)


}






val register = findViewById<Button>(R.id.rgbtn)

register.setOnClickListener {

val intent = Intent(this, RegisterActivity::class.java)
startActivity(intent)
}




val login = findViewById<Button>(R.id.loginbtn)

login.setOnClickListener {

val email = findViewById<EditText>(R.id.username)
val pass = findViewById<EditText>(R.id.passwordd)

val email1 = email.text.toString()
val password = pass.text.toString()

if (email.text.isEmpty() || pass.text.isEmpty()){
Toast.makeText(baseContext, "Please fill all fields", Toast.LENGTH_SHORT).show()
return@setOnClickListener


}



auth.signInWithEmailAndPassword(email1, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Toast.makeText(baseContext, "success",
Toast.LENGTH_SHORT).show()

val intent = Intent(this, MainActivity::class.java)
startActivity(intent)

} else {
// If sign in fails, display a message to the user.
Toast.makeText(baseContext, "Authentication failed.",
Toast.LENGTH_SHORT).show()
}
}
.addOnFailureListener{
Toast.makeText(baseContext, "Authentication failed. ${it.localizedMessage}",
Toast.LENGTH_SHORT).show()
}

}


}
}





MainActivity.kt
import android.app.Activity
import android.content.ContentValues.TAG
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.ktx.Firebase
import android.view.LayoutInflater
import android.widget.EditText
import android.widget.TableLayout
import android.widget.TableRow
import com.google.firebase.FirebaseApp
import com.google.firebase.auth.UserProfileChangeRequest
import com.google.firebase.database.*
import com.google.firebase.database.ktx.database
import com.google.firebase.firestore.auth.User
import java.util.*

class MainActivity : Activity() {

private lateinit var auth: FirebaseAuth
private lateinit var database: DatabaseReference
// ...

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)
FirebaseApp.initializeApp(this)
database = Firebase.database.reference



auth = Firebase.auth
val uid = auth.currentUser?.uid ?: ""
// Get a reference to the database location for the current user
val database = Firebase.database
val userRef = database.getReference("users/$uid")






val logout = findViewById<Button>(R.id.logout)

logout.setOnClickListener {

auth.signOut()

Toast.makeText(
baseContext, "logged out",
Toast.LENGTH_SHORT
).show()

val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)

}


val user = auth.currentUser
if (user != null) {
val db = FirebaseFirestore.getInstance()
db.collection("users").document(user.uid)
.get()
.addOnSuccessListener { document ->
if (document != null) {
val name1 = user.displayName
val name = user.displayName
val phone = document.get("phone") as String

val userInfoTextView = findViewById<TextView>(R.id.name21)
userInfoTextView.text = "Logged in as: $name"


}
}
.addOnFailureListener { exception ->
// Failed to retrieve user data

Toast.makeText(
baseContext, "Failed to retrieve user data",
Toast.LENGTH_SHORT
).show()
}
}







val addButton = findViewById<Button>(R.id.addButton)
val nameEditText = findViewById<EditText>(R.id.nameEditText)
val numberEditText = findViewById<EditText>(R.id.numberEditText)
val emailEditText = findViewById<EditText>(R.id.emailEditText)
val tableLayout = findViewById<TableLayout>(R.id.tableLayout)



fun addTableRow(contact: Contact) {

val tableRow = LayoutInflater.from(this).inflate(R.layout.table_row, null) as TableRow
tableRow.findViewById<TextView>(R.id.nameTextView).text = contact.name
tableRow.findViewById<TextView>(R.id.numberTextView).text = contact.number
tableRow.findViewById<TextView>(R.id.emailTextView).text = contact.email

val removeButton = tableRow.findViewById<TableRow>(R.id.removeButton)

removeButton.setOnClickListener {
// Remove the contact from the database
userRef.child(contact.id).removeValue()
tableLayout.removeView(tableRow)


}


tableLayout.addView(tableRow)
}


addButton.setOnClickListener {
val number = nameEditText.text.toString()
val name = numberEditText.text.toString()
val email = emailEditText.text.toString()

val database = Firebase.database
val userRef = database.getReference("users/$uid")
val childRef = userRef.push()
val contact = Contact(childRef.key ?: "vvv", name, number, email)

childRef.setValue(contact)
.addOnSuccessListener {
Toast.makeText(this, "success", Toast.LENGTH_SHORT).show()

// Retrieve the newly added contact and add it to the table
userRef.child(childRef.key!!)
.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
val newContact = snapshot.getValue(Contact::class.java)
if (newContact != null) {
// addTableRow(newContact)


userRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
// Clear the table before adding new rows


// Get the number of rows in the table layout
val rowCount: Int = tableLayout.childCount

// Remove all child views except the first one (header row)
if (rowCount > 1) {
tableLayout.removeViews(1, rowCount - 1)
}


// Iterate over each child node in the snapshot and add a new row to the table
for (childSnapshot in snapshot.children) {
val newContact = childSnapshot.getValue(Contact::class.java)
if (newContact != null) {

addTableRow(newContact)


}
}
}

override fun onCancelled(error: DatabaseError) {
// Handle error
}
})





}
}

override fun onCancelled(error: DatabaseError) {
// Handle error
}
})
}
.addOnFailureListener { exception ->
Toast.makeText(this, "failed", Toast.LENGTH_SHORT).show()
}
}





userRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
// Clear the table before adding new rows


// Get the number of rows in the table layout
val rowCount: Int = tableLayout.childCount

// Remove all child views except the first one (header row)
if (rowCount > 1) {
tableLayout.removeViews(1, rowCount - 1)
}


// Iterate over each child node in the snapshot and add a new row to the table
for (childSnapshot in snapshot.children) {
val newContact = childSnapshot.getValue(Contact::class.java)
if (newContact != null) {

addTableRow(newContact)


}
}
}

override fun onCancelled(error: DatabaseError) {
// Handle error
}
})


}

}







RegisterActivity.kt

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.google.firebase.FirebaseApp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.UserProfileChangeRequest
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.ktx.database
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize

class RegisterActivity : Activity() {

private lateinit var auth: FirebaseAuth



override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_register)

// Initialize Firebase Auth
auth = Firebase.auth
val login = findViewById<Button>(R.id.lgbtn)



login.setOnClickListener {

val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
}



val register = findViewById<Button>(R.id.signupbtn)

register.setOnClickListener {

val email = findViewById<EditText>(R.id.email)
val pass = findViewById<EditText>(R.id.password)
val phone = findViewById<EditText>(R.id.phone)
val name = findViewById<EditText>(R.id.name)

val email1 = email.text.toString()
val password = pass.text.toString()
val phone1 = phone.text.toString()
val name1 = name.text.toString()

if (email.text.isEmpty() || pass.text.isEmpty() || phone.text.isEmpty()) {
Toast.makeText(baseContext, "Please fill all fields", Toast.LENGTH_SHORT).show()
return@setOnClickListener


}

auth.createUserWithEmailAndPassword(email1, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Toast.makeText(baseContext, "success",
Toast.LENGTH_SHORT).show()



auth = Firebase.auth

val user = auth.currentUser
val profileUpdates = UserProfileChangeRequest.Builder()
.setDisplayName(name1) // Set the name
.build()
user?.updateProfile(profileUpdates)
?.addOnCompleteListener { task ->
if (task.isSuccessful) {
// Name updated successfully
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
} else {
// Name update failed
}
}

val userUpdates = hashMapOf<String, Any>(
"phone" to phone1 // Set the phone number
)
val db = FirebaseFirestore.getInstance()
db.collection("users").document(user?.uid.toString())
.set(userUpdates)
.addOnSuccessListener { documentReference ->
// Phone number added successfully
}
.addOnFailureListener { e ->
// Phone number addition failed
}




} else {
// If sign in fails, display a message to the user.
Toast.makeText(baseContext, "Authentication failed.",
Toast.LENGTH_SHORT).show()
}
}
.addOnFailureListener{
Toast.makeText(this, "error occurred ${it.localizedMessage}", Toast.LENGTH_SHORT)
.show()
}


}


}
}





activity_login.xml

<?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:background="@color/purple_700"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/signin"
android:text="Sign in"
android:textColor="@color/white"
android:textSize="35dp"
android:textStyle="bold"
android:layout_margin="50dp"
android:gravity="center"/>

<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/signin"
android:layout_marginStart="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
android:background="#30ffffff"
android:drawableLeft="@drawable/baseline_account_circle_24"
android:drawablePadding="20dp"
android:hint="Email"
android:padding="20dp"
android:textColor="@color/white"
android:textColorHint="@color/white" />

<EditText
android:id="@+id/passwordd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:layout_marginStart="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
android:background="#30ffffff"
android:drawableLeft="@drawable/baseline_password_24"
android:drawablePadding="20dp"
android:hint="Password"
android:inputType="textPassword"
android:padding="20dp"
android:textColor="@color/white"
android:textColorHint="@color/white" />

<com.google.android.material.button.MaterialButton
android:id="@+id/loginbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/passwordd"
android:layout_centerHorizontal="true"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:backgroundTint="@color/teal_200"
android:text="LOGIN" />

<TextView
android:id="@+id/forgotpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/loginbtn"
android:layout_centerHorizontal="true"
android:layout_marginStart="20dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:text="Forgot password?"
android:textColor="@color/white" />

<com.google.android.material.button.MaterialButton
android:id="@+id/rgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/forgotpass"
android:layout_centerHorizontal="true"
android:layout_marginStart="20dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:textColor="@color/white"
android:background="@android:color/transparent"
android:text="dont have an account? sign up now" />



<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/others"
android:layout_above="@id/socialicons"
android:text="or sign in with"
android:textColor="@color/white"
android:layout_centerHorizontal="true"/>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/socialicons"
android:layout_alignParentBottom="true"
android:gravity="center">


<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="20dp"
android:src="@drawable/google"/>
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="20dp"
android:src="@drawable/facebook"/>
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="20dp"
android:src="@drawable/twitter"/>

</LinearLayout>



</RelativeLayout>



activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/white"
tools:context=".RegisterActivity">


<TextView
android:id="@+id/name21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="100dp"
android:gravity="center"
android:text="Loading..."
android:textColor="@color/black"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.459"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</TextView>


<Button
android:id="@+id/logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Logout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</Button>

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/name21">


<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"
android:stretchColumns="*">


<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/header_shape"
android:gravity="center"
android:text="Name"
android:textSize="16sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/header_shape"
android:gravity="center"
android:text="Phone"
android:textSize="16sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@drawable/header_shape"
android:gravity="center"
android:text="Email"
android:textSize="16sp"
android:textStyle="bold" />


</TableRow>

</TableLayout>

</ScrollView>

<LinearLayout
android:layout_width="250dp"
android:layout_height="188dp"
android:layout_marginTop="300dp"
android:orientation="vertical"
android:background="@drawable/cell_shape"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/scrollview">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="horizontal">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:textStyle="bold"
android:gravity="center"
android:background="@drawable/header_shape"
android:text="Contact Details">
</TextView>

<EditText
android:id="@+id/nameEditText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="Name"
android:background="@drawable/cell_shape"
android:textAlignment="center" />

<EditText
android:id="@+id/numberEditText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="Number"
android:background="@drawable/cell_shape"
android:inputType="phone"
android:textAlignment="center" />

<EditText
android:id="@+id/emailEditText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="Email"
android:background="@drawable/cell_shape"
android:textAlignment="center" />
</LinearLayout>

</LinearLayout>


<Button
android:id="@+id/addButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="Add" />

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>




activity_register.xml

<?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:background="@color/purple_700"
tools:context=".MainActivity">

<TextView
android:id="@+id/signuptitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="Sign up"
android:textColor="@color/white"
android:textSize="35dp"
android:textStyle="bold" />

<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="2dp"
android:layout_marginBottom="10dp"
android:inputType="phone"
android:background="#30ffffff"
android:drawableLeft="@drawable/baseline_local_phone_24"
android:drawablePadding="20dp"
android:hint="Phone Number"
android:padding="20dp"
android:textColor="@color/white"
android:textColorHint="@color/white" />

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/signuptitle"
android:layout_centerHorizontal="true"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="#30ffffff"
android:drawableLeft="@drawable/baseline_account_circle_24"
android:drawablePadding="20dp"
android:hint="Name"
android:padding="20dp"
android:textColor="@color/white"
android:textColorHint="@color/white" />

<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/phone"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="#30ffffff"
android:drawableLeft="@drawable/baseline_email_24"
android:drawablePadding="20dp"
android:hint="Email"
android:padding="20dp"
android:textColor="@color/white"
android:textColorHint="@color/white" />

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/email"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="#30ffffff"
android:drawableLeft="@drawable/baseline_password_24"
android:drawablePadding="20dp"
android:hint="Password"
android:inputType="textPassword"
android:padding="20dp"
android:textColor="@color/white"
android:textColorHint="@color/white" />


<com.google.android.material.button.MaterialButton
android:id="@+id/signupbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/password"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="151dp"
android:layout_marginTop="60dp"
android:backgroundTint="@color/teal_200"
android:text="REGISTER"
android:textSize="15dp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/lgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/signupbtn"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:text="Already have an account?"
android:textColor="@color/white"
android:background="@android:color/transparent"
android:textSize="15dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/info"
android:layout_above="@id/socialicons"
android:text="or sign up with"
android:textColor="@color/white"
android:layout_centerHorizontal="true"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/socialicons"
android:gravity="center"
android:layout_alignParentBottom="true">

<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="20dp"
android:src="@drawable/google"/>
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="20dp"
android:src="@drawable/facebook"/>
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="20dp"
android:src="@drawable/twitter"/>
</LinearLayout>



</RelativeLayout>



Step 9: Right-click the layout folder then new > layout resource file gives the name table_row.xml and enter. then add the following code to this file

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/removeButton">



<TextView
android:id="@+id/numberTextView"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="1"
android:gravity="center"
android:textColor="#000"
android:background="@drawable/cell_shape"
android:textSize="13sp" />

<TextView
android:id="@+id/nameTextView"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="1"
android:gravity="center"
android:textColor="#000"
android:background="@drawable/cell_shape"
android:textSize="13sp" />


<TextView
android:id="@+id/emailTextView"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="2"
android:gravity="center"
android:textColor="#000"
android:background="@drawable/cell_shape"
android:textSize="13sp" />


</TableRow>



Step 10: add the following color code to the color.xml file

<color name="grey">#8BC34A</color>


Step 11: Create a new kotlin class file and name it Contact.kt and add the following code to this file


data class Contact(
val id: String,
val name: String,
val number: String,
val email: String
) {
// Default constructor
constructor() : this("", "", "", "")
}




Step 12: Add the following permissions to the manifest file

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>





Step 13: Right-click on the drawable folder then the drawable resource file. give the file name cell_shape.xml and add the following code to this file

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="@color/white"/>
<stroke android:width="1dp" android:color="#000000"/>
</shape>



Step 14: Right-click on the drawable folder then the drawable resource file. give the file name header_shape.xml and add the following code to this file

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="@color/grey"/>
<stroke android:width="1dp" android:color="#000000"/>
</shape>



done. now run the app.




Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.