我有一个包含一些项目的警报对话框。当用户单击菜单按钮而不提供任何关闭选项时,我需要关闭对话框。我怎样才能做到这一点?
这是我的代码
CharSequence[] cs = ques_cat.toArray(new CharSequence[ques_cat.size()]);
finalCharSequence[]css=ques_catidtoArray(newCharSequence[ques_catid.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(Gropinion_Questions.this);
builder.setTitle("Choose Category");
builder.setItems(cs, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
String ss = css[item].toString();
getSubCat(ss);
}
});
AlertDialog alert = builder.create();
alert.show();
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater=getMenuInflater();
menuInflater.inflate(R.menu.activity_main, menu);
if(alert !=null && alert.isShowing())
alert.dismiss();
return true;
}