How to close AlertDialog when I click on the ListView item


Here is my dialog code, there is a ListView in a dialog, I wanna close this dialog when I click on 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(;
        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);
               .setNegativeButton("Back", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // TODO Auto-generated method stub



I tried to put this code in onItemClick()



But it's not working.

Change .show() to dialog =; then put dialog.dismiss() to onItemClick().