I have implemented an AlertDialog with normal negative and positive button click listeners.
AlertDialog
When I called new DialogInterface.OnClickListener()>
new DialogInterface.OnClickListener()>
Its as simple as this:
button.setOnClickListener(view -> username = textView.getText());