AlertDialog.Builder对话框=新的AlertDialog.Builder(this) 在setOnItemClickListener()??
下没有(或没有显示)dismiss()方法特别是这是我的代码。
AlertDialog.Builder dialog = new AlertDialog.Builder(getApplicationContext());
dialog.setTitle("TITLE");
dialog.setView(view);
dialog.show();
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int pos,
long id) {
dialog.dismiss() // dismiss is not there.
}
});
感谢。
答案 0 :(得分:3)
这就是这些处理程序中始终如此:
您创建的不是Dialog,而是DialogBuilder。您需要按以下方式创建它:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setTitle("...");
builder.setMessage("message");
builder.setNegativeButton("OK", null);
AlertDialog dlg = builder.create();