我有一个alertdialog任何选项和2个按钮。当我按下第二个按钮(仅停止声音)时,我不想关闭对话框。
是否有任何属性可以保持对话框打开?
非常感谢你!
代码:
public void creaDialogTo(){
final String[] tonos = {"thinks.mp3", "life.mp3", "war.mp3"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select");
builder.setCancelable(false);
builder.setSingleChoiceItems(tones, -1,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
tone=tones[item];
sound1 =new SoundManager(getApplicationContext());
sound1.loadSound(tones[item]);
}
});
builder.setPositiveButton("Confirm",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
pref.setTone(tone);
sound1.stopsound();
}
});
builder.setNeutralButton("Stop sound",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
sound1.stopsound();
}
});
AlertDialog alert = builder.create();
alert.show();
}
答案 0 :(得分:5)
我想,你正在显示AlertDialog,默认按钮为Positive和Negative。相反,您可以创建一个Dialog,并将布局设置为此对话框的contentView,并手动设置两个按钮。在这里,您需要定义按钮单击事件的所有定义,并且不会出现默认按钮。因此,如果您没有在单击按钮时忽略对话框,则只需在按钮单击时不调用dialog.dismiss()。
编辑:中性按钮默认关闭对话框,尝试将其更改为否定按钮,如果仍然无法正常工作,那么请申请解决方案,我已在上面写过。