Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. val builder = AlertDialog.Builder(this, R.style.AlertDialogStyle)
  2. val inflater = this.layoutInflater
  3. val dialogView: View = inflater.inflate(R.layout.alert_dialog_et_layout, null)
  4.  
  5. builder.apply {
  6. setMessage(R.string.dialog_msg)
  7. setPositiveButton(R.string.dialog_accept_label, null)
  8. setNegativeButton(R.string.dialog_close_label, null)
  9. setView(dialogView)
  10. }
  11.  
  12. val alertDialog = builder.create()
  13. val positiveBtn = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
  14. val negativeBtn = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
  15. alertDialog.show()
  16.  
  17. positiveBtn.setOnClickListener {
  18. //do some stuff with data
  19. }
  20.  
  21. negativeBtn.setOnClickListener {
  22. alertDialog.cancel()
  23. }
  24.  
  25. java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement