Sat. Jul 13th, 2024

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<layout>
<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"
tools:context=".MainActivity"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dialogs example"
/>


<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt2"
android:text="custom"/>


</LinearLayout>
</layout>

MainActivity.kt

package com.androindian.dialogsex

import android.app.Dialog
import android.app.ProgressDialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.databinding.DataBindingUtil
import com.androindian.dialogsex.databinding.ActivityMainBinding
import com.google.android.material.transition.MaterialContainerTransform.ProgressThresholds

class MainActivity : AppCompatActivity() {
var binding:ActivityMainBinding?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding= DataBindingUtil.setContentView(this,R.layout.activity_main)


//custom

binding?.bt2?.setOnClickListener {

var dialog = Dialog(this)
dialog.setContentView(R.layout.custom)
dialog.setCancelable(false)

var button: Button?=null

button=dialog?.findViewById(R.id.bt3)

button?.setOnClickListener {
Toast.makeText(this@MainActivity,"Hello",Toast.LENGTH_LONG).show()
dialog.dismiss()
}

dialog.show()
}



}
}

custom.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:text="hello"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt3"
android:text="Click me"/>

<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ched"/>

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="radio"/>

<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

By Rajashekar

I’m (Rajashekar) a core Android developer with complimenting skills as a web developer from India. I cherish taking up complex problems and turning them into beautiful interfaces. My love for decrypting the logic and structure of coding keeps me pushing towards writing elegant and proficient code, whether it is Android, PHP, Flutter or any other platforms. You would find me involved in cuisines, reading, travelling during my leisure hours.

Leave a Reply

Your email address will not be published. Required fields are marked *