android - How to Refresh listview with custom adapter -


i need little solution refreshing listview after delete data database. realized can delete data database function of activity :

helper.delete(string.valueof(editid)); adapter.notifydatasetchanged(); break; 

and in dbhelper :

public void delete(string id) {     string[] args = {id};     getwritabledatabase().delete(table_name, "_id=?", args);     getwritabledatabase().close(); 

this code works deleting database , item, adapter.notifydatasetchanged(); listview refresh when closed application opened again. need way how refresh listview instantly. people used adapter.remove(position);, refresh instantly, call .notifydatasetchanged();. not worked custom adapter.

i used kind of adapter :

class listadapter extends cursoradapter{     @suppresswarnings("deprecation")     listadapter(cursor c){         super(mainactivity.this, c);     }      @override     public void bindview(view row, context ctxt, cursor c) {         // todo auto-generated method stub         listholder holder = (listholder)row.gettag();         holder.populatefrom(c, helper);              }      @override     public view newview(context ctxt, cursor c, viewgroup parent) {         // todo auto-generated method stub         layoutinflater inflater = getlayoutinflater();         view row = inflater.inflate(r.layout.custom_listview, parent, false);         listholder holder = new listholder(row);         row.settag(holder);         return (row);     }        }  static class listholder {     private textview nama = null, kategori=null;     private imageview icon=null;     private view row = null;      listholder(view row){         this.row=row;          nama=(textview)row.findviewbyid(r.id.main_title_name);         kategori=(textview)row.findviewbyid(r.id.sub_title_name);         icon=(imageview)row.findviewbyid(r.id.thumbnail);     }      void populatefrom(cursor c, dbhelper helper){         nama.settext(helper.getnamalok(c));         kategori.settext(helper.getkatglok(c));          byte[] bytearray = helper.getimglok(c);         bitmap bm = bitmapfactory.decodebytearray(bytearray, 0 ,bytearray.length);         icon.setimagebitmap(bm);      }                } 

sorry bad english, and.. hope there way solve this.. in advance.

you need use .notifydatasetchanged(); in correct way. remember method .notifydatasetchanged() says adapter the data has been changed , need refresh.

notifies attached observers underlying data has been changed , view reflecting data set should refresh itself.

so need change data set , notify adapter. cussoradapter, data set cursor, should change cursor below ways:

  1. requery() update cursor
  2. use changecursor(cursor cursor) change new cursor.

maybe this link helpful you.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -