這裏是我的對話框代碼,還有一個對話框中ListView
,我想關閉這個對話框,當我點擊ListView
:如何關閉AlertDialog當我點擊ListView項
public void createSearchDialog(final String[] Memo){
LayoutInflater factory = LayoutInflater.from(this);
View searchView = factory.inflate(R.layout.seach_dialog, null);
lv = (ListView) searchView.findViewById(R.id.search_list);
lv.setAdapter(new MyPerformanceArrayAdapter(this, Memo, memo_PW));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view, int position,long arg3) {
// TODO Auto-generated method stub
/// close dialog
}
});
searchBuilder = new AlertDialog.Builder(this);
searchBuilder.setTitle("Search")
.setView(searchView)
.setNegativeButton("Back", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
})
.show();
}
我試圖把此代碼在onItemClick()
searchBuilder.create().dismiss();
searchBuilder.create().cancel();
但它不工作。
AlertDialog在點擊按鈕BY DEFAULT時自動關閉。 – JoxTraex