我想在点击该item时候,该item变色,来表示处于选中状态。
原本我代码是这样的:listview.setOnItemClickListener(new OnItemClickListener () {public void onItemClick(AdapterView<?> arg0, View view, int position,
long arg3) {
index = position;for (int i = 0; i < DataList.size(); i ++) {
listview.getChildAt(i).setBackgroundColor(Color.BLACK);
//设置被选中状态的颜色,当取消选中的时候,又变回黑色
}view.setBackgroundColor(Color.GRAY);}
这样的问题是,处于隐藏状态的item当用滚动条拉到可见状态了,就getChildAt()就不管用了,或者干脆出异常了。
我用的SimpleAdapter生成的listview。
有没有什么办法,拿到指定的item。
  
  });