android - How to call notifydatasetchanged in PagerAdapter? -


i have 1 listview each item contains 1 viewpager. , every time scroll viewpage got error said pageradapter changed adapter's contents without calling pageradapter#notifydatasetchanged!

i tried set notifydatasetchanged in list adapter , pager adapter too, doesn't work.

here listadapter:

@override public view getview(final int position, view convertview, viewgroup parent) {     final viewholder holder;      if (convertview == null || convertview.gettag() == null) {         convertview = inflater.inflate(r.layout.activity_detail_item, parent, false);         holder = new viewholder(convertview);         convertview.settag(holder);      }     else{         holder = (viewholder) convertview.gettag();     }      item = data.get(position);     holder.tv_bill_nm.settext(item.getbill_nm());     holder.tv_use_intt_nm.settext(item.getuse_intt_nm());     holder.tv_cust_nm.settext(item.getcust_nm());     //item.getitem_rec() arraylist of object     pageadapter = new mypager_adapter(mcontext, item.getitem_rec());      makeindicator(holder.ll_indicator, pageadapter.getcount(), 0);     holder.vp_detail.setadapter(pageadapter);     //holder.vp_detail.getadapter().notifydatasetchanged();     holder.vp_detail.setonpagechangelistener(new viewpager.onpagechangelistener() {         @override         public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) {         }          @override         public void onpageselected(int position) {             log.d("page: ", position + "");             makeindicator(holder.ll_indicator, pageadapter.getcount(), position);         }          @override         public void onpagescrollstatechanged(int state) {          }     });     return convertview; } 

in viewpager of each list item views 3 of item.getitem_rec() @ page.

public class mypager_adapter extends pageradapter { private list<detail_rec_item> data; private context ctxt; public static int num; public static int idx; public static int k; public static int mod; private boolean donotifydatasetchangedonce = false;   public mypager_adapter(context ctxt, list<detail_rec_item> mdata) {     this.ctxt = ctxt;     this.data = mdata;     k= 0;     num = data.size(); //number of item     idx = num / 3; //number of page     mod = num % 3;     if (mod != 0)         idx++;     if (donotifydatasetchangedonce) {         donotifydatasetchangedonce = false;         notifydatasetchanged();     } }  @override public int getcount() {     if (donotifydatasetchangedonce) {         donotifydatasetchangedonce = false;         notifydatasetchanged();     }     return idx; }  @override public object instantiateitem(view container, int position) {     donotifydatasetchangedonce = true;     layoutinflater inflater = (layoutinflater) ctxt             .getsystemservice(context.layout_inflater_service);      linearlayout view = (linearlayout) inflater.inflate(r.layout.activity_detail_page, null);     int max = 3;     if (position == idx - 1)         max = mod;      (int j = 0; j < max; j++) {         linearlayout item = (linearlayout) inflater.inflate(r.layout.activity_detail_page_item, null);         textview tv_name = (textview) item.findviewbyid(r.id.tv_name);         textview tv_amount = (textview) item.findviewbyid(r.id.tv_amount);         tv_name.settext(data.get(k).getgds());         tv_amount.settext(commutil.currencydecrypt(data.get(k).getbill_amt()));         view.addview(item);         k++;     }      ((viewpager) container).addview(view, 0);     if (donotifydatasetchangedonce) {         donotifydatasetchangedonce = false;         notifydatasetchanged();     }     return view; }  @override public boolean isviewfromobject(view view, object obj) {     return view == ((view) obj); }  @override public void destroyitem(view container, int position, object object) {     // todo auto-generated method stub     donotifydatasetchangedonce = true;     ((viewpager) container).removeview((view) object); }   } 

i got error below:

e/androidruntime: fatal exception: main                                                                        java.lang.illegalstateexception: application's pageradapter changed adapter's contents without calling pageradapter#notifydatasetchanged! expected adapter item count: 2, found: 1 pager id: com.webcash.mobilebilling:id/vp_detail pager class: class android.support.v4.view.viewpager problematic adapter: class com.webcash.wcexpensesmanagementpjt_aos.adapter.mypager_adapter                                                                            @ android.support.v4.view.viewpager.populate(viewpager.java:1000)                                                                            @ android.support.v4.view.viewpager.populate(viewpager.java:952)                                                                            @ android.support.v4.view.viewpager$3.run(viewpager.java:251)                                                                            @ android.view.choreographer$callbackrecord.run(choreographer.java:791)                                                                            @ android.view.choreographer.docallbacks(choreographer.java:591)                                                                            @ android.view.choreographer.doframe(choreographer.java:560)                                                                            @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:777)                                                                            @ android.os.handler.handlecallback(handler.java:730)                                                                            @ android.os.handler.dispatchmessage(handler.java:92)                                                                            @ android.os.looper.loop(looper.java:176)                                                                            @ android.app.activitythread.main(activitythread.java:5419)                                                                            @ java.lang.reflect.method.invokenative(native method)                                                                            @ java.lang.reflect.method.invoke(method.java:525)                                                                            @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1046)                                                                            @ com.android.internal.os.zygoteinit.main(zygoteinit.java:862)                                                                            @ dalvik.system.nativestart.main(native method) 


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -