gpt4 book ai didi

android setNegativeButton 自定义对话框

转载 作者:行者123 更新时间:2023-11-29 00:17:55 27 4
gpt4 key购买 nike

我有自己的自定义对话框,如下所示:

public class BerekenDialog extends Dialog{
public BerekenDialog(Context context) {
super(context);
setContentView(R.layout.bereken_dialog_layout);

this.setTitle("Bereken");
//dostuff.
}
}

我的对话是这样开始的:

BerekenDialog bd = new BerekenDialog (this);
bd.show();

有没有办法将警告对话框中的否定、肯定和中性按钮添加到我的自定义对话框中?

最佳答案

get data from some spinners, make a calculation with the data and display it

您可以在不创建自定义对话框的情况下执行此操作,只有在构建器中创建它时才会创建正负按钮。没有办法实现它,您可以在带有按钮的 xml 布局中创建自己的布局。

在不使用自定义的情况下创建警报对话框:

    AlertDialog a = new AlertDialog.Builder(this)
.setTitle("Bereken")
.setView(getLayoutInflater().inflate( R.layout.bereken_dialog_layout,null))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// ok button
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// cancel button
}
}).create();
TextView tv = (TextView)a.findViewById(r.id.your_id); //use the instance of textview from layout of dialog
tv.setText("update"); //set is before displaying
a.show();

关于android setNegativeButton 自定义对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25251050/

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