我想显示一个对话框/弹出窗口,其中显示一条消息,显示"您确定要删除此条目吗?" 用一个按钮说"删除".当Delete被触摸时,应该删除该条目,否则什么都没有.
我为这些按钮编写了一个单击侦听器,但是如何调用对话框或弹出窗口及其功能?
我有一个EditText输入对话框.当我单击对话框上的"是"按钮时,它将验证输入,然后关闭对话框.但是,如果输入错误,我想保持在同一个对话框中.每次无论输入是什么,当我点击"否"按钮时,对话框应自动关闭.我怎么能禁用它?顺便说一句,我已经使用PositiveButton和NegativeButton作为对话框上的按钮.
android dialog android-alertdialog android-dialog android-dialogfragment
在Android应用程序中,我想在AlertDialog中显示自定义列表视图.
我怎样才能做到这一点?
API说警报对话框可以有一个,两个或三个按钮,但SDK只允许正面和负面按钮.那怎么可以添加第三个按钮?
在AlertDialog上的Android文档中,它提供了以下用于在AlertDialog中设置自定义视图的说明和示例:
如果要显示更复杂的视图,请查找名为"body"的FrameLayout并将视图添加到其中:
FrameLayout fl = (FrameLayout) findViewById(R.id.body);
fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud)
首先,非常明显的是这add()是一个错字,并且意味着addView().
我对使用R.id.body的第一行感到困惑.它似乎是AlertDialog的body元素......但是我不能在我的代码中输入它b/c它会产生编译错误.R.id.body在哪里被定义或分配或者其他什么?
这是我的代码.我试图setView(findViewById(R.layout.whatever)在构建器上使用但它没有用.我假设因为我没有手动充气吗?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title")
.setCancelable(false)
.setPositiveButton("Go", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
EditText textBox = (EditText) findViewById(R.id.textbox);
doStuff();
}
});
FrameLayout f1 = (FrameLayout)findViewById(R.id.body /*CURRENTLY an ERROR*/);
f1.addView(findViewById(R.layout.dialog_view));
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud) 我想显示一个带OK按钮的消息框.我使用了以下代码,但它导致带有参数的编译错误:
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("This is an alert with no consequence");
dlgAlert.setTitle("App Title");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();
Run Code Online (Sandbox Code Playgroud)
我该如何在Android中显示消息框?
我正在学习在Flutter中构建应用程序。现在我来警报对话框。我之前在Android和iOS中完成过这些操作,但是如何在Flutter中发出警报?
以下是一些相关的SO问题:
我想进行更一般的规范问答,所以我的答案如下。