android - why my adapter can't refresh it's view -


below adapter code , logs (log tag "jieke"), problem times can't display whole items in list, display 8 items meanwhile list size 10! see in log: getcount returns 10, getview called 10 times, still seen 8 views, why?

public class numberadapter extends baseadapter{     private layoutinflater minflater;     private arraylist<numbermodel> mphonenumberlist;      public numberadapter(context context, arraylist<numbermodel> phonenumberlist){         minflater = layoutinflater.from(context);         mphonenumberlist = phonenumberlist;     }      @override     public int getcount() {         if (mphonenumberlist != null) {             logutils.d("jieke", "count="+mphonenumberlist.size() );             return mphonenumberlist.size();         }         return 0;     }      @override     public object getitem(int position) {         if (position > -1 && mphonenumberlist != null && position < mphonenumberlist.size()) {             return mphonenumberlist.get(position);         }         return null;     }      public void setphonenumberlist(arraylist<numbermodel> phonenumberlist){         mphonenumberlist = phonenumberlist;     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {         logutils.d("jieke", "get view on position= " +position );         itemviewtag viewtag;         if (convertview == null)  {               convertview = minflater.inflate(r.layout.grid_item_custom_number, null);             viewtag = new itemviewtag((imageview) convertview.findviewbyid(r.id.item_image)                 ,(imageview) convertview.findviewbyid(r.id.item_phone)                 , (textview) convertview.findviewbyid(r.id.item_text));               convertview.settag(viewtag);           } else {               viewtag = (itemviewtag) convertview.gettag();           }         return convertview;       }      class itemviewtag {          protected imageview micon;           protected imageview mphone;         protected textview mname;         public itemviewtag(imageview icon, imageview phone, textview name){               this.mname = name;               this.micon = icon;               this.mphone = phone;       }   }   

}

here log:

05-13 21:20:24.975 d/absec.:customservicenumbertabitemview(18651):  reset adaptor this=1 05-13 21:20:24.975 d/absec.:jieke(18651): count=10 05-13 21:20:24.975 d/absec.:jieke(18651): count=10 05-13 21:20:24.975 d/absec.:customservicenumbertabitemview(18651):  notify change this=1 05-13 21:20:24.975 d/absec.:jieke(18651): count=10 05-13 21:20:24.975 d/absec.:jieke(18651): count=10 05-13 21:20:24.975 i/absec.:qbasetabview(18651): onresume 05-13 21:20:24.985 d/absec.:jieke(18651): count=10 05-13 21:20:24.985 d/absec.:jieke(18651): view on position= 0 05-13 21:20:24.985 d/absec.:jieke(18651): count=10 05-13 21:20:24.985 d/absec.:jieke(18651): view on position= 0 05-13 21:20:24.985 d/absec.:jieke(18651): count=10 05-13 21:20:24.985 d/absec.:jieke(18651): view on position= 0 05-13 21:20:24.985 d/absec.:jieke(18651): count=10 05-13 21:20:24.985 d/absec.:jieke(18651): view on position= 0 05-13 21:20:25.005 d/absec.:jieke(18651): view on position= 0 05-13 21:20:25.015 d/absec.:jieke(18651): view on position= 1 05-13 21:20:25.015 d/absec.:jieke(18651): view on position= 2 05-13 21:20:25.015 d/absec.:jieke(18651): view on position= 3 05-13 21:20:25.015 d/absec.:jieke(18651): view on position= 4 05-13 21:20:25.035 d/absec.:jieke(18651): view on position= 5 05-13 21:20:25.035 d/absec.:jieke(18651): view on position= 6 05-13 21:20:25.035 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.045 d/absec.:jieke(18651): view on position= 7 05-13 21:20:25.045 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.055 d/absec.:jieke(18651): view on position= 8 05-13 21:20:25.055 d/absec.:jieke(18651): view on position= 9 05-13 21:20:25.065 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.075 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.085 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.095 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.105 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.115 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.125 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.135 d/absec.:customserviceactivity(18651):  values=is_common=1 05-13 21:20:25.265 d/absec.:customservicenumberaddactivity(18651): addactivity destroy 

actually, need refresh gridview after mphonenumberlist changed (after mphonenumberlist.add() or mphonenumberlist.remove()) found using numberadapter.notifydatasetchanged() not work, every time create new adapter , reset gridview using gridview.setadapter(newnumberadapter), works , problem happened.

problem solved, after gridview.setadapter(newnumberadapter) add gridview.invalidateviews() works me!

i believe using asynctask.intialise arraylist arraylist<numbermodel> mphonenumberlist(which sending argument in constructor of adapter) in doinbackground(string... params) of asynctask like: mphonenumberlist=new arraylist<numbermodel> instead of creating instance in oncreate().

try solution.i believe adapter refreshed.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -