gpt4 book ai didi

android - 警报对话框两个按钮

转载 作者:IT老高 更新时间:2023-10-28 21:35:35 26 4
gpt4 key购买 nike

大家好,我有一个简单的问题,我有一个 alertDialog,我希望它显示我在这里搜索过的两个按钮,但似乎之前的选项不再起作用并且已被弃用。

任何人都知道执行此操作的新方法,您可以在下面看到我的代码不起作用。

  Button share = (Button) findViewById(R.id.btn_share);
share.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// call some other methods before that I guess...
AlertDialog alertDialog = new AlertDialog.Builder(PasswActivity.this).create(); //Read Update
alertDialog.setTitle("Uprgade");
alertDialog.setMessage("Upgrade Text Here");

alertDialog.setButton("Upgrade", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

});
alertDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

});



alertDialog.show(); //<-- See This!


}
});

最佳答案

Adding Buttons

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();

关于android - 警报对话框两个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8227820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com