Display the image on second listview when we click on first listview
<p>I want to be display the image on the second ListView when I click on first ListView. I write a code, Please see it:</p>

<pre><code>public class NewActivity extends Activity

{
private ListView lv1,lv2;

private static final String IMGKEY = "arrow";

private static final String TAG = "Dealer";

ArrayList&lt;HashMap&lt;String, Object&gt;&gt; contacts = new ArrayList&lt;HashMap&lt;String,Object&gt;&gt;();

HashMap&lt;String, Object&gt; hm;


//LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS
    ArrayList&lt;String&gt; listItems=new ArrayList&lt;String&gt;();

ArrayAdapter&lt;String&gt; adapter;

    ViewGroup vg;


private String lv_arr[]={"PHONE","CONTACTS","CALL HISTORY","DEALER","EDIT CONTACTS"};

@Override

public void onCreate(Bundle icicle)

{

super.onCreate(icicle);

setContentView(R.layout.main);


lv1 = (ListView)findViewById(R.id.ListView01);

lv2 = (ListView)findViewById(R.id.ListView02);

lv1.setSelection(3);



// By using setAdpater method in listview we an add string array in list.

lv1.setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1 , lv_arr));

lv1.setOnFocusChangeListener(new OnFocusChangeListener(){

    public void onFocusChange(View v, boolean hasFocus)

    {

            v.setBackgroundColor(hasFocus ? Color.BLUE : Color.YELLOW);

    }

    });


lv1.setClickable(true);


lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override

    public void onItemClick(AdapterView&lt;?&gt; av, View v, int pos, long id) {

        onListItemClick(v,pos,id);

        if (lv1.getAdapter().getItem(pos).equals(lv_arr[0]))

        {

            phone();

        }

        else if(lv1.getAdapter().getItem(pos).equals(lv_arr[1]))

        {

            contacts();  

            Toast.makeText(NewActivity.this, "Position: "+pos+",View: "+v+",Id: 
"+id+",AV: "+av, Toast.LENGTH_LONG).show();

        }

        else if(lv1.getAdapter().getItem(pos).equals(lv_arr[2]))

        {

            call();         

        }



        else if(lv1.getAdapter().equals(lv_arr[3]))

        {

            dealer();           

        }



        else if(lv1.getAdapter().equals(lv_arr[4]))

        {

            editcontacts();         

        }

        else

        {

            //final SimpleAdapter adapter = new SimpleAdapter(this, contacts, 
R.layout.image, new String[]{IMGKEY}, new int[]{R.id.imageview});

            lv2.setAdapter(adapter);

            lv2.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        }

    }

});





lv1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

    @Override

    public boolean onItemLongClick(AdapterView&lt;?&gt; av, View v, int pos, long id) {

        return onLongListItemClick(v,pos,id);

    }

});



lv2.setOnFocusChangeListener(new OnFocusChangeListener(){



    public void onFocusChange(View v, boolean hasFocus)

    {

            v.setBackgroundColor(hasFocus ? Color.BLUE : Color.YELLOW);

    }

    });



lv2.setClickable(true);



}







protected void onListItemClick(View v, int pos, long id) {

    Log.i(TAG, "onListItemClick id=" + id);

}



protected boolean onLongListItemClick(View v, int pos, long id) {

    Log.i(TAG, "onLongListItemClick id=" + id);

    return true;

}

//With the help of HashMap add Key, Values of Book, like name,price and icon path 

    public void phone() {

        lv2.clearTextFilter();

        hm = new HashMap&lt;String, Object&gt;();

        hm.put(IMGKEY, R.drawable.rarrowb); 

        contacts.add(hm);

        SimpleAdapter adapter = new SimpleAdapter(this, contacts, R.layout.image, 
new String[]{IMGKEY}, new int[]{R.id.imageview});

        //lv2.setItemChecked(0, true);

        lv2.setAdapter(adapter);

           lv2.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    }





public void call() {

        lv2.destroyDrawingCache();

        hm = new HashMap&lt;String, Object&gt;();

        hm.put(IMGKEY, R.drawable.rarrowb); 

        contacts.add(hm);

        SimpleAdapter adapter = new SimpleAdapter(this, contacts, R.layout.image, 
new String[]{IMGKEY}, new int[]{R.id.imageview});

        //lv2.setItemChecked(1, true);

        lv2.setAdapter(adapter);

        lv2.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        }





public void dealer() {

        lv2.destroyDrawingCache();

        hm = new HashMap&lt;String, Object&gt;();

        hm.put(IMGKEY, R.drawable.rarrowb); 

        contacts.add(hm);

        SimpleAdapter adapter = new SimpleAdapter(this, contacts, R.layout.image, 
new String[]{IMGKEY}, new int[]{R.id.imageview});

        //lv2.setItemChecked(2, true);

        lv2.setAdapter(adapter);

        lv2.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        }



    public void editcontacts() {

        lv2.destroyDrawingCache();

        hm = new HashMap&lt;String, Object&gt;();

        hm.put(IMGKEY, R.drawable.rarrowb); 

        contacts.add(hm);

        lv2.setAdapter(new ArrayAdapter&lt;String&gt;
(this,android.R.layout.simple_list_item_1 , lv_arr));

        //SimpleAdapter adapter = new SimpleAdapter(this, contacts, R.layout.image, 
new String[]{IMGKEY}, new int[]{R.id.imageview});

        lv2.setItemChecked(3, true);

        lv2.setAdapter(adapter);

        lv2.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        }





    public void contacts() {


        lv2.destroyDrawingCache();

        hm = new HashMap&lt;String, Object&gt;();

        hm.put(IMGKEY, R.drawable.rarrowb); 

        contacts.add(hm);

        SimpleAdapter adapter = new SimpleAdapter(this, contacts, R.layout.image, 
new String[]{IMGKEY}, new int[]{R.id.imageview});

        lv2.setItemChecked(4, true);

        lv2.setAdapter(adapter);

        lv2.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        }

    }
</code></pre>

<p>My problem is that when I click on another row then first image has not destroyed. I want to be only one image on the second ListView. Please help me to correct this code, thanks in advance.</p>
