我有一个alertdialog的任何选项和2个按钮。当我按下第二个按钮(只停止声音)时,我不想关闭对话框。不要关闭alertdialog通过点击一个按钮 - Android的
是否有任何属性保持对话框打开?
非常感谢!
代码:
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();
}
可以发布代码你正在使用的警报对话框 –
@Ramkiran谢谢你,这是代码 –
然后调用builder.dismiss()只在确认按钮。无需调用停止按钮的解除方法 –