我正在尝试制作一个自定义对话框以在此对话框中显示一个视图.这是生成器代码:
I'm trying to make a custom dialog to show a view in this dialog. This is the Builder code:
//Getting the layout
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog_simple,
(ViewGroup) findViewById(R.id.rlDialogSimple));
//Change Text and on click
TextView tvDialogSimple = (TextView) layout.findViewById(R.id.tvDialogSimple);
tvDialogSimple.setText(R.string.avisoComprobar);
Button btDialogSimple = (Button) layout.findViewById(R.id.btDialogSimple);
btDialogSimple.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Do some stuff
//Here i want to close the dialog
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(AcPanelEditor.this);
builder.setView(layout);
AlertDialog alert = builder.create();
alert.show();
所以,我想关闭 btDialogSimple 的 onClick 中的对话框.我该怎么做?我不知道如何从 onclicklistener 中调用dismiss方法.
So, i want to dismiss the dialog in the onClick of btDialogSimple. How i can do it? I don't know how to call the dismiss method from inside a onclicklistener.
我的按钮有自定义布局,所以我不想制作 builder.setPositiveButton.
My buttons have a custom layout, so i don't want to make a builder.setPositiveButton.
有什么想法吗?
您必须将 AlertDialog 保存到您的父类属性中,然后使用如下内容:
You have to save the AlertDialog to your parent class property, then use something like this:
class parentClass ........ {
private AlertDialog alert=null;
........
public void onClick(View v) {
//Do some stuff
//Here i want to close the dialog
if (parentClass.this.alert!=null)
parentClass.this.alert.dismiss();
}
........
this.alert = builder.create();
this.alert.show();
}
这篇关于关闭自定义对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 GPS 获取用户的当前位置Get user#39;s current location using GPS(使用 GPS 获取用户的当前位置)
requestLocationUpdate() 抛出的 IllegalArgumentExceptionIllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 抛出的 IllegalArgumentException)
LocationManager 的 getLastKnownLocation 有多可靠,多久更How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新
如何检测位置提供者?GPS 或网络提供商How to detect Location Provider ? GPS or Network Provider(如何检测位置提供者?GPS 或网络提供商)
在应用启动期间获取当前位置Get current location during app launch(在应用启动期间获取当前位置)
locationManager.getLastKnownLocation() 返回 nulllocationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)