在Android应用程序中,我想在AlertDialog中显示自定义列表视图.
我怎样才能做到这一点?
当我按下按钮时,我想保持对话框打开.目前正在关闭.
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();
Run Code Online (Sandbox Code Playgroud) 点击PositiveButton后我可以不解雇我的AlertDialog吗?
我想继续在对话框中显示我的ArrayAdapter listWords上的更新内容.
这是我的代码.
AlertDialog.Builder sayWindows = new AlertDialog.Builder(MapActivity.this);
final EditText saySomething = new EditText(MapActivity.this);
sayWindows.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
say = userName + " Says: "+saySomething.getText();
showPosition.setText(say);
}
});
sayWindows.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
sayWindows.setAdapter(listWords, null);
sayWindows.setView(saySomething);
sayWindows.create().show();
Run Code Online (Sandbox Code Playgroud) 我有一个带有自定义视图的DialogFragment,其中包含两个文本字段,用户可以在其中输入用户名和密码.单击肯定按钮时,我想验证用户在解除对话框之前确实输入了一些内容.
public class AuthenticationDialog extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.authentication_dialog, null))
.setPositiveButton(getResources().getString(R.string.login), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO
}
})
.setNegativeButton(getResources().getString(R.string.reset), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO
}
});
return builder.create();
}
}
Run Code Online (Sandbox Code Playgroud)
那么如何防止对话被解雇呢?我应该覆盖一些方法吗?
主题有点说明了所有..我正在向用户请求PIN码,如果他们输入了PIN码,请单击"确定"按钮并且PIN码不正确我想显示Toast但保持对话框打开.此刻它自动关闭..当然这是非常微不足道的事情要纠正但尚未找到答案.
谢谢..
我是Xamarin的新手,我不知道如何在c#中执行以下操作.我想在单击Positive/Negative按钮时阻止alertdialog关闭.我需要先对输入进行一些验证.如果输入正确,则对话框可以关闭,否则我将显示带有说明的消息.基本上,我有以下代码:
private void CreateAddProjectDialog() {
//some code
var alert = new AlertDialog.Builder (this);
alert.SetTitle ("Create new project");
alert.SetView (layoutProperties);
alert.SetCancelable (false);
alert.SetPositiveButton("Create", HandlePositiveButtonClick);
alert.SetNegativeButton("Cancel", HandelNegativeButtonClick);
}
private void HandlePositiveButtonClick (object sender, EventArgs e) {
//Do some validation here and return false (prevent closing of dialog) if invalid, else close....
}
Run Code Online (Sandbox Code Playgroud)
现在,我在StackOverflow上重新发布以下文章:如何在单击按钮时阻止对话框关闭
我认为下面的代码(取自线程)有解决方案,但我不知道如何重写我的c#代码来实现Java:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Test for preventing dialog close");
builder.setPositiveButton("Test",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
//Do nothing here because we …Run Code Online (Sandbox Code Playgroud) 我正在将我的Android应用程序转换为使用片段.以前,我有一个活动,现在是一个片段.因此,不能再使用此代码:
showDialog(CONFIRM_ID);
// ...
@Override
public Dialog onCreateDialog(int id) {
// Create the confirmation dialog...
}
Run Code Online (Sandbox Code Playgroud)
在Fragment对象内部,我需要显示一个确认对话框,确认后会将我返回到对象以进行状态更新.
例如
我怎么能做到这一点?请提供工作示例代码.
我正在尝试设置一个自定义AlertDialog,它有2个按钮,取消和一个肯定的按钮.我需要点击正面按钮,我可以更改文本,而不是关闭对话框.
粗流是正按钮会说"发送",点击它会变为"正在发送...",然后代码会将一些数据发送到我们的服务器,如果响应为真,则关闭对话框,如果是false或timeouts等显示错误消息(Toast)并保持对话框打开.
我有代码将数据发送到服务器,处理响应等,我只是想不到如何编辑AlertDialog类实现这个.有谁知道我会怎么做呢?
目前的测试代码:
AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setView(getActivity().getLayoutInflater().inflate(R.layout.dialog_single_text, null));
b.setTitle("Forgotten Password");
b.setMessage("Please enter your email");
b.setPositiveButton("Send", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getActivity(), "Sending...", Toast.LENGTH_SHORT).show();
}
});
b.create().show();
Run Code Online (Sandbox Code Playgroud) 我正在使用AlertDialog.Builder来构建我的对话框,它有一个需要填充的EditText,我想阻止关闭对话框,而不是.在正面按钮的onClickListener中,我可以检查editText是否已填充,但我不知道如何阻止关闭...
builder.setPositiveButton("title", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
if(...){
//can close
}else{
//prevent closing
}
}
})
Run Code Online (Sandbox Code Playgroud)