我在课程中列出了练习清单。用户可以修改此练习以显示或不显示。当他点击练习时,改变状态(显示或不显示)练习。对数据库所做的所有更改都可以正常工作。但是当用户进行更改时,当您滚动图片时,“检查”在出现的行中显示不正确。
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;
}
}