本文介绍了如何解雇AlertDialog Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建AlertDialog包含4个按钮
I created AlertDialog that contains 4 buttons
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()方法后,将其关闭,我该怎么办呢?在此先感谢。
I want to dismiss it after SetBackground() method, how can I do this?thanks in advance.
推荐答案
其实没有任何取消()
或辞退()
从AlertDialog.Builder类的方法。
Actually there is no any cancel()
or dismiss()
method from AlertDialog.Builder Class.
所以不是 AlertDialog.Builder OptionDialog
使用 AlertDialog
实例。
像,
AlertDialog OptionDialog = new AlertDialog.Builder(this).create();
现在,只需拨打 OptionDialog.dismiss();
background.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SetBackground();
// here I want to dismiss it after SetBackground() method
OptionDialog.dismiss();
}
});
这篇关于如何解雇AlertDialog Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!