java.lang.IllegalStateException:不调用PagerAdapter#notifyDataSetChanged

时间:2014-06-03 10:46:39

标签: android android-viewpager

您好,
                我在我的活动中有一个viewpager。viewpager在刷页面时显示不同的值。但它显示了一个非法状态异常。我无法解决这个问题,因为我是一个更新鲜的android.So请帮帮我。我的logcat输出是:

        06-03 06:32:56.644: E/InputEventReceiver(1502): Exception dispatching input event.
        06-03 06:32:56.644: E/MessageQueue-JNI(1502): Exception in MessageQueue callback: handleReceiveCallback
        06-03 06:32:56.774: E/MessageQueue-JNI(1502): java.lang.IllegalStateException: The application's Pager`enter code here`Adapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 2, found: 5 Pager id: com.exalt.vts:id/summarypager Pager class: class android.support.v4.view.ViewPager Problematic adapter: class com.exalt.vts.DashBoard$MyPagerAdapter

我的代码是

    private class MyPagerAdapter extends PagerAdapter {

        public int getCount() {
            return vd.length;
        }

    public Object instantiateItem(ViewGroup collection, int position) {

        LayoutInflater inflater = (LayoutInflater) collection.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View page= inflater.inflate(R.layout.sliding_summary_page,null);
       TextView license = (TextView)page.findViewById(R.id.licenseSummary);
       TextView driver=(TextView) page.findViewById(R.id.driverSummary);
       TextView km=(TextView) page.findViewById(R.id.kmSummary);
       TextView loc=(TextView) page.findViewById(R.id.locationSummary);
       TextView en=(TextView) page.findViewById(R.id.engineSummary);
       TextView ac=(TextView) page.findViewById(R.id.acSummary);

       license.setText(licenseArray[position]);
      driver.setText(driverArray[position]);
       km.setText(KmArray[position]);
       loc.setText(LocArray[position]);
       en.setText(engArray[position]);
       ac.setText(acArray[position]);
        ((ViewPager) collection).addView(page,0);



        return page;
    }

@Override
public void notifyDataSetChanged() {
    // TODO Auto-generated method stub
    viewPager.setCurrentItem(0);
    super.notifyDataSetChanged();
}
    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((View) arg2);

    }


    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == ((View) arg1);

    }

    @Override
    public Parcelable saveState() {
        return null;
    }
}

0 个答案:

没有答案