ListView : In simple listview, while changing the background color of the view in listview then it also changes below while scrolling
<p>this is my code. here the background color of selected row is changing. but after scrolling the bachground color of not selected view is also changed.i want to prevent this problem. any help?</p>

<pre><code>  public class ListDemoActivity extends ListActivity {
         String[] names = {
                    "Dwight",
                    "Kennedy",
                    "Johnson",
                    "Richard",
                    "Gerald",
                    "Jimmy",
                    "Ronald",
                    "George",
                    "Bill",
                    "B. Bush",
                    "Rana"
            };
         View view;
         int posn = -1;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            setListAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, names));
        }
        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {



    Log.i("Log", "Clicked posn"+position);
    Log.i("Log", "id is: "+id);
    if(posn == -1)
    {
        v.setBackgroundResource(R.color.blue);
    //  l.getChildAt(position).setBackgroundResource(R.color.blue);
        view = v;
        posn = position;    
    }
    else if (posn == position)
    {
        v.setBackgroundResource(R.color.blue);
        //l.getChildAt(position).setBackgroundResource(R.color.blue);
    }
    else
    {
        Log.i("Log", "Count of child:  "+l.getChildCount());
    //  View view = l.getChildAt(posn);
    //  Log.i("Log", "Position: "+view.)
        //view.setBackgroundResource(R.color.black);

        //view = l.getChildAt(position);
        //view.setBackgroundResource(R.color.blue);

        view.setBackgroundResource(R.color.black);
        v.setBackgroundResource(R.color.blue);
        view = v;
        posn = position;
    }
    }
}
</code></pre>
