Skip to content

Instantly share code, notes, and snippets.

@rahulkhatri19
Created July 13, 2019 13:12
Show Gist options
  • Save rahulkhatri19/630435b26410e8cab6cb04958cfe1e70 to your computer and use it in GitHub Desktop.
Save rahulkhatri19/630435b26410e8cab6cb04958cfe1e70 to your computer and use it in GitHub Desktop.
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.example.flipkotlinfirst.R
import com.example.flipkotlinfirst.util.AlertDialogUtility
import kotlinx.android.synthetic.main.activity_alert_dialog.*
import kotlinx.android.synthetic.main.dialog_layout.view.*
class AlertDialogActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_alert_dialog)
// For custom dilaog box inside file.
btn_alert.setOnClickListener {
val layoutBuilder = LayoutInflater.from(this).inflate(R.layout.dialog_layout, null)
val builder = AlertDialog.Builder(this).setView(layoutBuilder)
builder.show()
layoutBuilder.btn_ok.setOnClickListener {
Toast.makeText(this, "Alert Text: " + layoutBuilder.et_name.text.toString(), Toast.LENGTH_SHORT).show()
}
}
// for custom dilaog box outside file.
// Static Alert dilaog to used in more than one file with minimum code.
btn_alert_custom.setOnClickListener {
AlertDialogUtility.alertDialog(this, "Hello I am Alert Dialog", 1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment