我在每一行都有一个带有复选框的列表视图,当我选择任何复选框然后滚动屏幕时,每个项目的复选框都会随机更改,我的意思是取消选中它变成选中,有时它保持取消选中,然后当我再次向上滚动时,选中的变成取消选中,我发现这个问题Android listview with checkbox problem,用户说这对他们有帮助,但我不明白我应该做什么,请帮忙
这是我的适配器
class RestaurantAdapter extends BaseAdapter {
private static LayoutInflater inflater = null;
private ArrayList<HashMap<String, String>> data;
Activity activity;
public RestaurantAdapter(Activity activity,
ArrayList<HashMap<String, String>> data) {
// TODO Auto-generated constructor stub
this.activity = activity;
this.data = data;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (vi == null)
vi = inflater.inflate(R.layout.restaurant_multi_select_list_item,
null);
TextView name = (TextView) vi
.findViewById(R.id.restaurant_multi_select_title);
ImageView image = (ImageView) vi
.findViewById(R.id.restaurant_multi_select_list_item_image);
CheckBox cb = (CheckBox) vi
.findViewById(R.id.restaurant_multi_select_checkBox);
HashMap<String, String> restaurant = data.get(position);
name.setText(restaurant.get("name"));
image.setImageResource(Integer.parseInt(restaurant.get("image")));
return vi;
}
}