android - CursorAdapter in Listview -


i'm using cursoradapter reading database in listview. have checkbox in each item of list when checkbox checked user favorite column in database change yes , item added favorite.

everything ok , favorite column changed when scroll , down list checkbox going unchecked. , if restarting app checkbox have been checked

what should problem:

sorry bad english:

cursoradapter class:

public class myadapter extends cursoradapter {      context b;        layoutinflater inflater;     @suppresswarnings("deprecation")     public myadapter(context context, cursor c) {         super(context, c);         inflater = layoutinflater.from(context);         b= (context) context;     }      @suppresswarnings("unused")     @override     public void bindview(view view, context context, final cursor cursor) {         // todo auto-generated method stub          textview tv1 = (textview)view.findviewbyid(r.id.txt_name);         textview tv2 = (textview)view.findviewbyid(r.id.txt_numer);          tv1.settext(cursor.getstring(2));         tv2.settext(cursor.getstring(3));          final int pos = cursor.getposition();          final checkbox repeatchkbx = (checkbox)view.findviewbyid(r.id.favorite_check);          string me = cursor.getstring(cursor.getcolumnindex("like"));          if (me.equals("yes")) {             repeatchkbx.setchecked(true);         } else {             repeatchkbx.setchecked(false);         }          repeatchkbx.setonclicklistener(new onclicklistener() {              @override             public void onclick(view view) {                 mydatabase mydatabase = new mydatabase(b);                 sqlitedatabase mydb = mydatabase.getwritabledatabase();                 cursor.movetoposition(pos);                  if (repeatchkbx.ischecked()) {                                        mydb.execsql("update list set = 'yes' id = " + cursor.getstring(1));                  }else{                     mydb.execsql("update list set = 'no' id = " + cursor.getstring(1));                             }             }         });          }          protected context getactivity() {             // todo auto-generated method stub             return null;         }          @override         public view newview(context context, cursor cursor, viewgroup parent) {             return inflater.inflate(r.layout.item, parent, false);         }     } 

screenshot:

enter image description here

problem when update database database going update not cursor adapt cursor adapter ,so have use

 changecursor(newcursor); 

in adapter after updating database. hope you.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -