我尝试更改列表视图中所选项目的背景,当我滚动列表视图时,我选择了更多项目。我知道它发生了,因为我回收了我的项目列表,但我找不到解决这个问题的方法
这是我的代码: 类 BabyAdapter 扩展 ArrayAdapter {
BabyHolder babyholder;
BabyAdapter(ArrayList<BabyHolder> list) {
super(BabyNames.this, R.layout.namerow, R.id.tvName, list);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
TextView tv = (TextView) row.getTag();
if(tv == null){
tv = (TextView) row.findViewById(R.id.tvName);
row.setTag(tv);
}
row.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
v.setBackgroundColor(Color.BLUE);
}
});
babyholder = getItem(position);
tv.setTag(Integer.valueOf(position));
tv.setText(babyholder.name);
return row;
}
}
public BabyHolder getItem(int position) {
return (((BabyAdapter) getListAdapter()).getItem(position));
}
谢谢您的帮助 :]