Dismiss dialog in android
<p>I have a imageView in onCreate method where I am using method showList. This is code:</p>

<pre><code>action_bar_log_in_icon.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {

                                allResults.clear();
                                allResults.add(action_bar_log_in_icon);
                                allResults.add(action_bar_data_privacy_icon);
                                allResults.add(action_bar_vCard_icon);
                                allResults.add(action_bar_email_icon);
                                showList();
                            }
                        });
</code></pre>

<p>and code method showList:</p>

<pre><code>private void showList() {
            final ListDialog listDialog = new ListDialog(this);
            listDialog.setCanceledOnTouchOutside(true);

            final ListView lv = (ListView) listDialog
                    .findViewById(R.id.spinnerlist);

            if(lAdapter == null){
                lAdapter = new ListAdapter(getBaseContext(),
                    R.layout.spinner_item,
                    (ArrayList&lt;ImageView&gt;) allResults);
            }

            lv.setAdapter(lAdapter);
            lv.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                        int position, long id) {
                    switch(position){
                    case 0:
                        intent = new Intent(ActionBarMain2.this, LoginActivity.class);
                        startActivity(intent);
                        break;
                    case 1:
                        intent = new Intent(ActionBarMain2.this, LoginActivity.class);
                        startActivity(intent);
                        break;
                    case 2:
                        intent = new Intent(ActionBarMain2.this, vCard_view.class);
                        startActivity(intent);
                        break;
                    case 3:
                        intent = new Intent(ActionBarMain2.this, EmailView.class);
                        startActivity(intent);
                        break;
                    }
                    listDialog.dismiss();
                }

            });
            WindowManager.LayoutParams WMLP = listDialog.getWindow()
                    .getAttributes();
            WMLP.gravity = Gravity.TOP | Gravity.RIGHT;
            WMLP.y = 50;
            WMLP.width = 100;
            listDialog.getWindow().setAttributes(WMLP);

                listDialog.show();



        }
</code></pre>

<p>This solution work and if I click on imageview my list is showing, but problem is when I click again on the same imageview. List is still visible. How I can do when I click first time my list is showing and when I click again my list dismiss etc?</p>
