我没有使用负面和正面按钮。我需要关闭对话框,但dialog.dismiss()没有效果。
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setView(view);
alert.setCancelable(false);
dialog = alert.create();
goButton.setOnClickListener(new View.OnClickListener() { //goButton is inside view which is inflated inside the dialog
@Override
public void onClick(View view) {
age = (String)spinner.getSelectedItem();
if(gender == null){
Utils.makeToast(context, "Select your gender");
}else if(age == null || age.toLowerCase().contains("age") || age.equals("")){
spinner.performClick();
}else{
Utils.makeToast(context, (String)spinner.getSelectedItem() + " - gender: " +gender);
editor.putInt("age", Utils.getIntOrZero(age));
editor.putString("gender", gender);
editor.commit();
dialog.dismiss(); // called but not working
}
}
});
alert.show();
答案 0 :(得分:11)
这并不是解雇,因为您AlertDialog
上的AlertDialog.dismiss
与所显示的alert.show()
不同。换句话说,您正在调用dialog.dismiss()
并使用dialog.show()
。要解决此问题,请致电{{1}}。