Change background image of listview on item selected from adapter
<p>In my getView method from my listadapter, When i select an item in the list, i want this selected item background image to take a specific image and the other items from the list to take the default background image. I implemented a for loop to do this but when i select an item from the row, the background image doesn't change.. can we change background image from a button click ? and where am i wrong because i believe my code is ok. Here is the part where the selected item is checked.</p>

<p>pos = position;</p>

<pre><code>    size = main.items.size()-1;

    holder.row.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            int x = position + 1;

               for (int i=0;i&lt;size;i++){

                   holder.row.setBackgroundResource(R.drawable.layer_unselected);

                   holder.text.setTextColor(Color.WHITE);

                   if (x==main.items.size()-1){

                       holder.row.setBackgroundResource(R.drawable.layer_selected);

                       holder.text.setTextColor(Color.BLACK);

                   }    

               }

               System.out.println("selected layer: "+ x );

               System.out.println("selected layer pos: "+pos);

               System.out.println("selected layer size: "+size);


               main.selectItem(position+1);

        }
    });
</code></pre>
