ListView does not show correct data when scrolling after the update date

advertisements

I put a list of exercises in the lesson. The user can modify this exercise to show or not. When he clicks on the exercise, changing the status (show or not show) exercise. All changes made to the database works fine. But when the user made ​​the change, when you scroll through the picture "check" is displayed not correctly in emerging lines.

protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 ....
 db = new MyDatabase(this);
 getOnListExes();
 db.close();
}
....
    public  void getOnListExes() {
    onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
    sAdapter = new SimpleCursorAdapter(this,
            R.layout.exeslist, onListExesChek,
            new String[] {"exes_bodypart", "exes_name", "exes_name"},
            new int[] {R.id.exesPartlist_chek, R.id.exesNamelist_chek,
 R.id.chek_img}) {

        public View getView(int position, View convertView, ViewGroup parent) {
                View row = super.getView(position, convertView, parent);
                TextView exesPartlist_chek =
(TextView) row.findViewById(R.id.exesPartlist_chek);
                TextView exesNamelist_chek =
(TextView) row.findViewById(R.id.exesNamelist_chek);
                ImageView imageGender =
(ImageView) row.findViewById(R.id.chek_img);
                return row;
        }
    };
    sAdapter.setViewBinder(new MyViewBinder());
    listExesChek.setAdapter(sAdapter);
   }

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    positionChek = position;
    selectExe_id = Long.toString(id);
    db = new MyDatabase(this);
    onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
    onListExesChek.moveToPosition(positionChek);

    if (
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
        onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()) {
        if(prog_man.equals("1")) {
            prog_man_chek = new ContentValues();
            prog_man_chek.put("prog_man_chek", "0");
            int upProg_man_chek = db.setExe(prog_man_chek,
 selectExe_id);
        }
        if(prog_woman.equals("1")) {
            prog_woman_chek = new ContentValues();
            prog_woman_chek.put("prog_woman_chek", "0");
            int upProg_woman_chek = db.setExe(prog_woman_chek,
 selectExe_id);
    } else {
        if(prog_man.equals("1")) {
            prog_man_chek = new ContentValues();
            prog_man_chek.put("prog_man_chek", "1");
            int upProg_man_chek = db.setExe(prog_man_chek,
 selectExe_id);
        }
        if(prog_woman.equals("1")) {
            prog_woman_chek = new ContentValues();
            prog_woman_chek.put("prog_woman_chek", "1");
            int upProg_woman_chek = db.setExe(prog_woman_chek,
 selectExe_id);
        }
    }
    db.close();
    updateView(position);
}

void updateView(int index){
    db = new MyDatabase(this);
    onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
    onListExesChek.moveToPosition(positionChek);
    View v = listExesChek.getChildAt(index -
            listExesChek.getFirstVisiblePosition());
    if (
    onListExesChek.getInt(onListExesChek.getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
    onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()
    ) {
        ImageView imageGender = (ImageView) v.findViewById(R.id.chek_img);
        imageGender.setImageResource(R.drawable.check);
    } else {
        ImageView imageGender = (ImageView) v.findViewById(R.id.chek_img);
        imageGender.setImageResource(R.drawable.notchek);
    }
    db.close();
}

class MyViewBinder implements SimpleCursorAdapter.ViewBinder {
    public boolean setViewValue (View view, Cursor cursor, int columnIndex) {
        switch (view.getId()) {
        case R.id.chek_img:
            if (onListExesChek.getInt(onListExesChek.
getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()
                    ) {
                ((ImageView) view).setImageResource(R.drawable.check);
            } else {
                (
(ImageView) view).setImageResource(R.drawable.notchek);
            }
        return true;
      }
      return false;
    }
  }


ListViews recycle views, which means at first a base set of list entries is inflated from XML.

for more check

android listview displays false data after scrolling (custom adapter)

ListView is not showing correct values after scrolling

both works for me