我用AlertDialog.Builder dialog = new AlertDialog.Builder(this)定义了一个dialog,可是在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. }});
1 回答
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
你创建的是DialogBuilder而不是Dialog,你应该这样创建dialog: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();
添加回答
举报
0/150
提交
取消