我有一些警告对话框,我的问题是当我点击右上角的十字(X)时没有setNegative按钮时如何关闭警告对话框。
imgmain.setImageResource(imgID);
imgmain.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
/*Intent MyIntentDetailItem=new Intent(getBaseContext(), ViewDetailItemFullscreen.class);
Other_class.setItemCode(timgName);
startActivity(MyIntentDetailItem);*/
LayoutInflater li = LayoutInflater.from(ViewDetailItem.this);
final View inputdialogcustom = li.inflate(R.layout.activity_view_detail_item_fullscreen2, null);
final AlertDialog.Builder alert = new AlertDialog.Builder(ViewDetailItem.this);
ImageView btnclose = (ImageView) inputdialogcustom.findViewById(R.id.btnclosepopup);
btnclose.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//DOING SOMETHING
}
});
}
}
答案 0 :(得分:0)
假设您有X
图片,那么您可以按照以下方式执行此操作,
private static AlertDialog.Builder alert; // at class level
其余代码相同
alert = new AlertDialog.Builder(ViewDetailItem.this);
btnclose.setOnClickListener ( new OnClickListener ()
{
@Override
public void onClick ( View view )
{
alert.dismiss(); // Add this line in your code.
}
});
答案 1 :(得分:0)
您可以使用解除功能myalertdialog.dismiss()
答案 2 :(得分:0)
使用finish()退出警告对话框...