android - notifyDataSetChanged not refreshing listview fragment -


i have searched as on google, have search as can find on here, @ loss, co-workers unhelpful, want @ , tell me missing causing listview not refresh data. logs showing is containing correct number of elements not showing in list.

public class shiftlistviewfragment extends fragment {     private static int total_items = 11;     private static string tag = "shiftlistviewfragment";     private listview mlistview;     private shiftitemarrayadapter madapter;     private arraylist<shiftitem> mshiftitems = new arraylist<shiftitem>();     ;     private arraylist<shiftitem> displayshiftitems = new arraylist<shiftitem>();     private button mpageleftbutton;     private button mpagerightbutton;      private int mpagenumber = 0;     private int mpageindex = 0;      public static shiftlistviewfragment newinstance() {         shiftlistviewfragment shiftlistviewfragment = new shiftlistviewfragment();          return shiftlistviewfragment;     }      public shiftlistviewfragment() {      }      public void populateshiftitems() {         date clockin = new date("08/17/2015 11:11 am");         date clockout = new date("08/17/2015 11:11 pm");         date breaktimein = new date("08/17/2015 10:11 pm");         date breaktimeout = new date("08/17/2015 10:11 pm");         (int = 0; < 28; i++) {             shiftitem shiftitem =                     new shiftitem(new shiftdto(clockin, clockout, breaktimein, breaktimeout));             mshiftitems.add(shiftitem);         }     }      public void populatedisplayshifts() {         int lowerbound = mpageindex * 11;         int uppbound = lowerbound + 11;         if (uppbound > mshiftitems.size()) {             uppbound = mshiftitems.size();         }         arraylist<shiftitem> shifts = new arraylist<shiftitem>();         (int = lowerbound; < uppbound; i++) {             shifts.add(mshiftitems.get(i));         }         displayshiftitems.clear();         madapter.clear();         displayshiftitems.addall(shifts);         madapter.notifydatasetchanged();     }      public int getpagenumber() {         int pages = 0;         pages = mshiftitems.size() / total_items;          if (pages % 11 != 0) {             pages++;         }         log.d("tag", "totalpages " + pages);         log.d("tag", "shift items count:" + mshiftitems.size());          return pages;     }      private void initviews(view view) {         mlistview = (listview)view.findviewbyid(r.id.shift_report_list);         mpageleftbutton = (button)view.findviewbyid(r.id.btn_page_left);         mpagerightbutton = (button)view.findviewbyid(r.id.btn_page_right);     }      @nullable     @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {          final view view = inflater.inflate(r.layout.shift_list_report_fragment, null);         initviews(view);         populateshiftitems();         mpagenumber = getpagenumber();         madapter = new shiftitemarrayadapter(getactivity(), r.layout.shift_list_item,                 displayshiftitems,                 r.color.shift_list_item_bg);         mlistview.setadapter(madapter);         populatedisplayshifts();         mpagerightbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 mpageindex++;                 if (mpageindex > mpagenumber - 1) {                     mpageindex = 0;                 }                 populatedisplayshifts();                 log.d(tag, "page:" + mpageindex + " actual items in list:" + madapter.getcount());             }         });          mpageleftbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 mpageindex--;                 if (mpageindex < 0) {                     mpageindex = mpagenumber - 1;                 }                 populatedisplayshifts();                  log.d(tag, "page:" + mpageindex + " actual items in list:" + madapter.getcount());             }         });          return view;     } } 

and adapter

public class shiftitemarrayadapter extends arrayadapter<shiftitem> {     private layoutinflater mlayoutinflater;     private int malternatecolorresource;      public shiftitemarrayadapter(context context, int resource,             arraylist<shiftitem> shiftitems,             @colorres int colorresid) {         super(context, resource, shiftitems);         this.malternatecolorresource = colorresid;         this.mlayoutinflater = layoutinflater.from(context);     }      /**      * applies background resources in alternating fashion, based on view's position.      */     protected void applybackground(int position, @nonnull view convertview) {         if (position % 2 == 0) {             convertview.setbackgroundresource(malternatecolorresource);         } else {             convertview.setbackgroundresource(android.r.color.white);         }     }      @override     public view getview(int position, view convertview, viewgroup parent) {         viewholder viewholder = null;          string clockedin = getitem(position).getintime();         string clockedout =                 getitem(position).getouttime();          if (convertview == null) {             viewholder = new viewholder();             convertview = mlayoutinflater.inflate(r.layout.shift_list_item, null);             viewholder.clockedintextview = (textview)convertview.findviewbyid(r.id.time_in);             viewholder.clockedouttextview = (textview)convertview.findviewbyid(r.id.time_out);             viewholder.dashedtextview = (textview)convertview.findviewbyid(r.id.dash);             viewholder.breaktotaltextview = (textview)convertview.findviewbyid(r.id.break_total);             viewholder.totaltimetextview = (textview)convertview.findviewbyid(r.id.total_time);              viewholder.clockedintextview.settext(clockedin);             viewholder.clockedouttextview.settext(clockedout);              convertview.settag(viewholder);         } else {             viewholder = (viewholder)convertview.gettag();         }          date breaksin = new date("11/11/2015 11:20 am");         date breaksout = new date("11/11/2015 12:20 pm");         string breakhours = string.valueof(                 datehelper.gettimeduration(breaksin, breaksout, false).getstandardhours());         string breakmin = string.valueof(                 datehelper.gettimeduration(breaksin, breaksout, false).getstandardminutes());         viewholder.breaktotaltextview.settext(breakhours + " hr " + breakmin + " min ");          applybackground(position, convertview);          return convertview;     }      private class viewholder {         public textview clockedintextview;         public textview dashedtextview;         public textview clockedouttextview;         public textview breaktotaltextview;         public textview totaltimetextview;     } } 

any , appreciated.

apparently there bug in android list items in listview have trouble defining actual size, solution set list_item.xml specific height instead of wrap_content.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -