title: How to call notifydatasetchanged in PagerAdapter?
body: <p>I have one listview which each item contains one ViewPager. And every time I scroll my ViewPage I got error said that PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!</p>
  
  <p>I tried to set notifyDataSetChanged in my list adapter and pager adapter too, but it doesn't work.  </p>
  
  <p>Here is my ListAdapter:</p>
  
  <pre><code>@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() is 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;
  }
  </code></pre>
  
  <p>In ViewPager of each list item views only 3 of item.getITEM_REC() at a page.</p>
  
  <pre><code>public class MyPager_Adapter extends PagerAdapter {
  private List&lt;Detail_Rec_Item&gt; 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&lt;Detail_Rec_Item&gt; 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;
  
      for (int j = 0; j &lt; 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);
  }
  
  
  }
  </code></pre>
  
  <p>I got the error as below:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         java.lang.IllegalStateException: The application's PagerAdapter changed the 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
                                                                             at android.support.v4.view.ViewPager.populate(ViewPager.java:1000)
                                                                             at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
                                                                             at android.support.v4.view.ViewPager$3.run(ViewPager.java:251)
                                                                             at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
                                                                             at android.view.Choreographer.doCallbacks(Choreographer.java:591)
                                                                             at android.view.Choreographer.doFrame(Choreographer.java:560)
                                                                             at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
                                                                             at android.os.Handler.handleCallback(Handler.java:730)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                             at android.os.Looper.loop(Looper.java:176)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5419)
                                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:525)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
                                                                             at dalvik.system.NativeStart.main(Native Method)
  </code></pre>