【发布时间】:2013-01-28 23:39:25
【问题描述】:
我创建了包含 4 个按钮的 AlertDialog
OptionDialog = new AlertDialog.Builder(this);
OptionDialog.setTitle("Options");
LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = li.inflate(R.layout.options, null, false);
background = (Button) v.findViewById(R.id.bkgSpinnerLabel);
SoundVib = (Button) v.findViewById(R.id.SoundVibSpinnerLabel);
OptionDialog.setView(v);
OptionDialog.setCancelable(true);
OptionDialog.setNeutralButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
background.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SetBackground();
// here I want to dismiss it after SetBackground() method
}
});
SoundVib.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent soundVibIntent = new Intent(SebhaActivity.this, EditPreferences.class);
startActivity(soundVibIntent);
}
});
OptionDialog.show();
我想在 SetBackground() 方法之后关闭它,我该怎么做? 提前致谢。
【问题讨论】:
-
请使用java命名约定:方法和变量名应该以小写字母开头。
-
使用 dialog.dismiss();在 SetBackground(); 之后
-
@DaanGeurts -
AlertDialog.Builder类中没有任何dismiss()方法。 -
@user370305 对,我错过了那个,你的答案应该有效
-
OptionDialog.setView(null);
标签: android android-alertdialog dismiss