I have a list with a flag in each line, when I select any flag, and then scroll the screen, the flags for each element change evenly, I mean, to uncheck its check, and sometimes it doesn’t uncheck, and then when I scroll again, the verified one goes down, I found this Android listview question with a checkbox problem , and users say it helps them, but I can’t understand what sholud I do and help please
this is my adapter
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) {
this.activity = activity;
this.data = data;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
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;
}
}
source
share