我的 android 代码可以通过 onClick 事件将第一个可见列表视图项目的背景颜色更改为绿色,但是当我向下滚动列表视图并尝试单击列表时,绿色不会出现。如何解决这个问题任何帮助将不胜感激。我附上了我的代码片段。
   public void onItemClick( AdapterView<?> parent, View item,   
                                  int position, long id) {
     for(int i=0; i<parent.getChildCount(); i++)
           {
               Log.d("TAG", "Number of times printed");
                if(i == position)
                {
                          parent.getChildAt(position).setBackgroundColor(Color.GREEN);
                         // Log.d("TAG","Green at position :: " + position);
                }
                else
                {
                          parent.getChildAt(i).setBackgroundColor(Color.GRAY);
                }
            }
}