【发布时间】:2018-08-12 10:38:00
【问题描述】:
我是一个 android 工作室的新手,以前在 swift 中编码。我试图研究在 android studio 中创建一个警报视图,但其中大多数没有给我超过 2 个警报选择。很快,我会做类似的事情:
@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)
}
我如何在 android studio 中做到这一点?任何帮助表示赞赏。以下是我尝试过的,但在此之后卡住了,因为我无法发出另一个警报
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();
【问题讨论】:
标签: android