I am new to an android studio and previously was coding in swift. I tried to look into creating an alert view in an android studio but most of them don't give me more than 2 alert selections. In swift, I would be doing something like :
@IBAction func showAlertButtonTapped(_ sender: UIButton) {
// create the alert
let alert = UIAlertController(title: "Hi there", message: "You have three selections to choose from", preferredStyle: UIAlertControllerStyle.alert)
// the actions and handler to decide what happens when user clicks on it
alert.addAction(UIAlertAction(title: "Selection 1", style: UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: "Selection 2", style: UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
}
How am I able to do it in the android studio?? Any help is appreciated. Below is what I tried, but stuck after this as I can't put another alert
AlertDialog alertDialog = new AlertDialog.Builder(MyActivity.this).create();
alertDialog.setTitle("Hey there!");
alertDialog.setMessage("You have three selections to choose from");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Selection 1",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();