Kotlin SQLite Database - Android Studio

In this example, I will show you how to create SQLite Database in kotlin And how to Add, Update, Delete data in SQLite. .

Kotlin SQLite Database Example Video

  • You can also go through this video explanation.

Kotlin SQLite Database(Add, Update, Delete) Example

Creating a New Project

  • So first create a new Android Studio project using Kotlin.
  • Once the project is loaded come inside the activity_main.xml and remove the Hello World TextView.
Android studio project screen

Step 1:
Open build.gradle and add following dependency and rebuild the project.
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
Step 2:
Create new Package:- recyclerviewclick
RecyclerTouchListener.kt
Create new class RecyclerTouchListener.kt under recyclerviewclick package and Add following code.
package com.kotlinkatta.sqlitedatabase.recyclerviewclick

import android.content.Context
import android.view.GestureDetector
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.MotionEvent
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener

class RecyclerTouchListener(context: Context?, recyclerView: RecyclerView?, private val clickListener: ClickListener?) : OnItemTouchListener {

private val gestureDetector: GestureDetector

interface ClickListener {
fun onClick(view: View?, position: Int)
fun onLongClick(view: View?, position: Int)
}

override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
val child = rv.findChildViewUnder(e.x, e.y)
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
clickListener.onClick(child, rv.getChildAdapterPosition(child))
}
return false
}

override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}

init {
gestureDetector = GestureDetector(context, object : SimpleOnGestureListener() {

override fun onSingleTapUp(e: MotionEvent?): Boolean {
return true
}

override fun onLongPress(e: MotionEvent) {
val child = recyclerView!!.findChildViewUnder(e.x, e.y)
if (child != null && clickListener != null) {
clickListener.onLongClick(child, recyclerView.getChildAdapterPosition(child))
}
}
})
}
}
Step 3:
Create new Package:- model
UserInfoModel.kt
Create new class UserInfoModel.kt under model package and Add following code.
package com.kotlinkatta.sqlitedatabase.model

class UserInfoModel(var key_id: Int , val first_name:String, val last_name:String, val gender:String, val email:String, val address:String) {
}
Step 4:
Create new Package:- database
DatabaseHandler.kt
Create new class DatabaseHandler.kt under database package and Add following code.
package com.kotlinkatta.sqlitedatabase.database

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

class DatabaseHandler(context: Context): SQLiteOpenHelper(context, DATABASE_NAME,null, DATABASE_VERSION) {
companion object {
private val DATABASE_VERSION = 1
private val DATABASE_NAME = "USERINFODATABASE"

/* UserInfo Data*/
val userinfo_table_name = "UserInfoTable"
val userinfo_key_id = "key_id"
val userinfo_first_name = "first_name"
val userinfo_last_name = "last_name"
val userinfo_gender = "gender"
val userinfo_email = "email"
val userinfo_address = "address"

val create_userifo_table = ("CREATE TABLE " + userinfo_table_name + "("
+ userinfo_key_id + " integer primary key autoincrement,"
+ userinfo_first_name + " TEXT,"
+ userinfo_last_name + " TEXT,"
+ userinfo_gender + " TEXT,"
+ userinfo_email + " TEXT,"
+ userinfo_address + " TEXT" + ")")
}

override fun onCreate(db: SQLiteDatabase?) {
db?.execSQL(create_userifo_table)
}

override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
db!!.execSQL("DROP TABLE IF EXISTS " + userinfo_table_name)
onCreate(db)
}
}
Step 5:
DatabaseSingleton.kt
Create new class DatabaseSingleton.kt under database package and Add following code.
package com.kotlinkatta.sqlitedatabase.database

import android.content.Context
import android.database.sqlite.SQLiteDatabase

object DatabaseSingleton {
var database: SQLiteDatabase? = null
fun getInstance(activity: Context?): SQLiteDatabase? {
if (database == null) database =
DatabaseHandler(activity!!).getWritableDatabase()
return database
}
}
Step 6:
UserInfoTableManager.kt
Create new class UserInfoTableManager.kt under database package and Add following code.
package com.kotlinkatta.sqlitedatabase.database

import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.util.Log
import com.kotlinkatta.sqlitedatabase.model.UserInfoModel

import java.util.*

class UserInfoTableManager {
var sqLiteDatabase: SQLiteDatabase? = null
constructor(activity: Context?) {
sqLiteDatabase = DatabaseSingleton.getInstance(activity)
}

// Insert UserInfo Data
fun insert_UserInfo_Data(model: UserInfoModel) {
val cv = ContentValues()
cv.put(DatabaseHandler.userinfo_first_name, model.first_name)
cv.put(DatabaseHandler.userinfo_last_name, model.last_name)
cv.put(DatabaseHandler.userinfo_gender, model.gender)
cv.put(DatabaseHandler.userinfo_email, model.email)
cv.put(DatabaseHandler.userinfo_address, model.address)
sqLiteDatabase!!.insert(DatabaseHandler.userinfo_table_name, null, cv)
}

// get UserInfo Data
fun get_UserInfo_Data(): List<UserInfoModel> {
val userInfoModelList: MutableList<UserInfoModel> = ArrayList()
val selectQuery = "select * from " + DatabaseHandler.userinfo_table_name
val cursor = sqLiteDatabase!!.rawQuery(selectQuery, null)
if (cursor.moveToFirst()) {
do {
var key_id = cursor.getInt(cursor.getColumnIndex(DatabaseHandler.userinfo_key_id))
var first_name = cursor.getString(cursor.getColumnIndex(DatabaseHandler.userinfo_first_name))
var last_name = cursor.getString(cursor.getColumnIndex(DatabaseHandler.userinfo_last_name))
var gender = cursor.getString(cursor.getColumnIndex(DatabaseHandler.userinfo_gender))
var email = cursor.getString(cursor.getColumnIndex(DatabaseHandler.userinfo_email))
var address = cursor.getString(cursor.getColumnIndex(DatabaseHandler.userinfo_address))

val userInfoModel= UserInfoModel(key_id = key_id, first_name = first_name, last_name = last_name, gender = gender, email = email, address = address)
userInfoModelList.add(userInfoModel)
} while (cursor.moveToNext())
}
return userInfoModelList
}

// get UserInfo Data Count
fun get_UserInfo_Data_Count(): Int {
var count = 0
val countQuery = "SELECT * FROM " + DatabaseHandler.userinfo_table_name
val cursor = sqLiteDatabase!!.rawQuery(countQuery, null)
if (cursor != null && !cursor.isClosed) {
count = cursor.count
cursor.close()
}
return count
}

// delete UserInfo Data
fun delete_UserInfo_Data(userInfo_key_id: String) {
sqLiteDatabase!!.beginTransaction()
try {
sqLiteDatabase!!.delete(DatabaseHandler.userinfo_table_name, DatabaseHandler.userinfo_key_id.toString() + "=" + userInfo_key_id, null)
sqLiteDatabase!!.setTransactionSuccessful()
} catch (e: Exception) {
Log.d("delete", "Error while trying to delete UserInfo Data")
} finally {
sqLiteDatabase!!.endTransaction()
}
}

// Update UserInfo Data
fun update_UserInfo_Data(userInfo_key_id: String, first_name: String, last_name: String, gender: String, email: String, address: String): Boolean {
val contentValues = ContentValues()
contentValues.put(DatabaseHandler.userinfo_first_name, first_name)
contentValues.put(DatabaseHandler.userinfo_last_name, last_name)
contentValues.put(DatabaseHandler.userinfo_gender, gender)
contentValues.put(DatabaseHandler.userinfo_email, email)
contentValues.put(DatabaseHandler.userinfo_address, address)
sqLiteDatabase!!.update(DatabaseHandler.userinfo_table_name, contentValues, DatabaseHandler.userinfo_key_id.toString() + "=?", arrayOf(userInfo_key_id))
return true
}
}
Step 7:
Create new userinfo_row.xml file under layout and Add following code.

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

<androidx.cardview.widget.CardView
android:layout_margin="10dp"
app:cardCornerRadius="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">

<TextView
android:id="@+id/txt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20dp" />

<TextView
android:id="@+id/txt_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="17dp" />

<TextView
android:id="@+id/txt_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="17dp" />

<TextView
android:id="@+id/txt_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="17dp" />

</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Step 8:
Create new Package:- adapter
UserInfoAdapter.kt
Create new class UserInfoAdapter.kt under adapter package and Add following code.
package com.kotlinkatta.sqlitedatabase.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.kotlinkatta.sqlitedatabase.R
import com.kotlinkatta.sqlitedatabase.model.UserInfoModel
import kotlinx.android.synthetic.main.userinfo_row.view.*

class UserInfoAdapter (val userList: List<UserInfoModel>) : RecyclerView.Adapter<UserInfoAdapter.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.userinfo_row, parent, false)
return ViewHolder(v)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val usermodel : UserInfoModel = userList[position]
holder.txt_name.text = "Name :" + usermodel.first_name + " " + usermodel.last_name
holder.txt_gender.text = "Gender : " + usermodel.gender
holder.txt_email.text = "Email : " + usermodel.email
holder.txt_address.text = "Address : " + usermodel.address
}

override fun getItemCount(): Int {
return userList.size
}

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val txt_name = itemView.txt_name
val txt_gender = itemView.txt_gender
val txt_email = itemView.txt_email
val txt_address = itemView.txt_address
}
}
Step 9:
activity_main.xml
Add following code into activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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=".MainActivity">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
app:srcCompat="@android:drawable/ic_menu_add" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Step 10:
MainActivity.kt
Add following code into MainActivity.kt
package com.kotlinkatta.sqlitedatabase

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.kotlinkatta.sqlitedatabase.adapter.UserInfoAdapter
import com.kotlinkatta.sqlitedatabase.database.UserInfoTableManager
import com.kotlinkatta.sqlitedatabase.model.UserInfoModel
import com.kotlinkatta.sqlitedatabase.recyclerviewclick.RecyclerTouchListener
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
lateinit var userInfo_List: List<UserInfoModel>

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

findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
val intent = Intent(applicationContext, AddInfoActivity::class.java)
startActivity(intent)
finish()
}

val recyclerView = findViewById<RecyclerView>(R.id.recyclerview)
var layoutManager = LinearLayoutManager(this)
recyclerview.layoutManager = layoutManager

var userInfo_data_count = UserInfoTableManager(this).get_UserInfo_Data_Count()
if (userInfo_data_count == 0 ){
Toast.makeText(applicationContext,"No Data Available", Toast.LENGTH_SHORT).show()
} else {
userInfo_List = UserInfoTableManager(this).get_UserInfo_Data()
val adapter = UserInfoAdapter(userInfo_List)
recyclerView.adapter = adapter
}

// RecyclerView onClick & onLongClick
recyclerView.addOnItemTouchListener(RecyclerTouchListener(applicationContext, recyclerView, object : RecyclerTouchListener.ClickListener {
override fun onClick(view: View?, position: Int) {
val recyle_sel: UserInfoModel = userInfo_List.get(position)
val intent = Intent(applicationContext, UpdateDeleteInfoActivity::class.java)
val str_key_id = recyle_sel.key_id.toInt().toString()
intent.putExtra("intent_key_id", str_key_id)
intent.putExtra("intent_first_name", recyle_sel.first_name)
intent.putExtra("intent_last_name", recyle_sel.last_name)
intent.putExtra("intent_gender", recyle_sel.gender)
intent.putExtra("intent_email", recyle_sel.email)
intent.putExtra("intent_address", recyle_sel.address)
startActivity(intent)
finish()
}

override fun onLongClick(view: View?, position: Int) {
val recyle_sel: UserInfoModel = userInfo_List.get(position)
}
}))
}
}
Step 11:
Create new Empty Activity:- AddInfoActivity
AddInfoActivity.kt
Add following code into AddInfoActivity.kt
package com.kotlinkatta.sqlitedatabase

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import com.kotlinkatta.sqlitedatabase.database.UserInfoTableManager
import com.kotlinkatta.sqlitedatabase.model.UserInfoModel
import kotlinx.android.synthetic.main.activity_add_info.*

class AddInfoActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_info)

val btn_submit= findViewById<Button>(R.id.btn_submit)
btn_submit.setOnClickListener {
var str_first_name = et_first_name.text.toString()
var str_last_name = et_last_name.text.toString()
var str_gender = et_gender.text.toString()
var str_email_id = et_email_id.text.toString()
var str_address = et_address.text.toString()

if(str_first_name!!.equals("") || str_last_name!!.equals("") || str_gender!!.equals("") || str_email_id!!.equals("") || str_address!!.equals("")){
Toast.makeText(applicationContext,"Enter All Fields.",Toast.LENGTH_SHORT).show()
}else{
UserInfoTableManager(applicationContext).insert_UserInfo_Data(UserInfoModel(0, str_first_name, str_last_name, str_gender,str_email_id,str_address))
Toast.makeText(applicationContext,"Info Added Successfully. ",Toast.LENGTH_SHORT).show()
func_finish()
}
}
}

private fun func_finish() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}

override fun onBackPressed() {
func_finish()
}
}
Step 12:
activity_add_info.xml
Add following code into activity_add_info.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".AddInfoActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Info"
android:textSize="30dp"
android:gravity="center"
android:textColor="#000000"
android:fontFamily="sans-serif-black"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gender"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email Id"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_email_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Address"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/btn_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:background="@color/colorAccent"
android:layout_margin="10dp"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Step 13:
Create new Empty Activity:- UpdateDeleteInfoActivity
UpdateDeleteInfoActivity.kt
Add following code into UpdateDeleteInfoActivity.kt
package com.kotlinkatta.sqlitedatabase

import android.app.AlertDialog
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import com.kotlinkatta.sqlitedatabase.database.UserInfoTableManager
import kotlinx.android.synthetic.main.activity_update_delete_info.*

class UpdateDeleteInfoActivity : AppCompatActivity() {
var intent_key_id = ""
var intent_first_name = ""
var intent_last_name = ""
var intent_gender = ""
var intent_email = ""
var intent_address = ""

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

val i = intent
val bd = i.extras
if (bd != null) {
intent_key_id = bd.getString("intent_key_id")!!
intent_first_name = bd.getString("intent_first_name")!!
intent_last_name = bd.getString("intent_last_name")!!
intent_gender = bd.getString("intent_gender")!!
intent_email = bd.getString("intent_email")!!
intent_address = bd.getString("intent_address")!!
}

et_first_name_ud.setText(intent_first_name)
et_last_name_ud.setText(intent_last_name)
et_gender_ud.setText(intent_gender)
et_email_id_ud.setText(intent_email)
et_address_ud.setText(intent_address)

val btn_update= findViewById<Button>(R.id.btn_update)
btn_update.setOnClickListener {
var str_first_name = et_first_name_ud.text.toString()
var str_last_name = et_last_name_ud.text.toString()
var str_gender = et_gender_ud.text.toString()
var str_email_id = et_email_id_ud.text.toString()
var str_address = et_address_ud.text.toString()

if(str_first_name!!.equals("") || str_last_name!!.equals("") || str_gender!!.equals("") || str_email_id!!.equals("") || str_address!!.equals("")){
Toast.makeText(applicationContext,"Enter All Fields",Toast.LENGTH_SHORT).show()
}else{
UserInfoTableManager(applicationContext).update_UserInfo_Data(intent_key_id, str_first_name, str_last_name, str_gender,str_email_id,str_address)
Toast.makeText(applicationContext,"Info Updated Successfully. ",Toast.LENGTH_SHORT).show()
func_finish()
}
}

val btn_delete= findViewById<Button>(R.id.btn_delete)
btn_delete.setOnClickListener {
val builder = AlertDialog.Builder(this)
builder.setMessage("Are you sure you want to Delete Info?")
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.setPositiveButton("Yes"){dialogInterface, which ->
UserInfoTableManager(applicationContext).delete_UserInfo_Data(intent_key_id)
Toast.makeText(applicationContext,"Info Deleted Successfully. ",Toast.LENGTH_SHORT).show()
func_finish()
}
builder.setNegativeButton("No"){dialogInterface, which -> }
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(false)
alertDialog.show()
}
}

private fun func_finish() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}

override fun onBackPressed() {
func_finish()
}
}
Step 14:
activity_update_delete_info.xml
Add following code into activity_update_delete_info.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".UpdateDeleteInfoActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update Delete Info"
android:textSize="30dp"
android:gravity="center"
android:textColor="#000000"
android:fontFamily="sans-serif-black"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_first_name_ud"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_last_name_ud"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gender"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_gender_ud"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email Id"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_email_id_ud"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Address"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:inputType="none"
android:id="@+id/et_address_ud"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:id="@+id/btn_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update"
android:textSize="20dp"
android:background="@color/colorAccent"/>

<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:id="@+id/btn_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete"
android:textSize="20dp"
android:background="@color/colorAccent"/>

</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Output :



Comments