Android viewpager里面嵌套使用listview或者ExpandableList时,在移出子view时报IllegalArgumentExcept...

 

    log如下:

06-22 23:45:50.110: E/ActivityThread(6217): Don't dump hprof file because it is not in monkey test! false, false
06-22 23:45:50.120: E/AndroidRuntime(6217): FATAL EXCEPTION: main
06-22 23:45:50.120: E/AndroidRuntime(6217): java.lang.IllegalArgumentException: The observer is null.
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.database.Observable.unregisterObserver(Observable.java:59)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.widget.BaseAdapter.unregisterDataSetObserver(BaseAdapter.java:42)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.widget.AbsListView.onDetachedFromWindow(AbsListView.java:2373)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.View.dispatchDetachedFromWindow(View.java:9818)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2283)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2281)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2281)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2281)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3601)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3581)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.view.ViewGroup.removeView(ViewGroup.java:3529)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.support.v4.view.ViewPager.removeView(ViewPager.java:1321)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at com.jeejen.largecalendar.ui.YiJiAct$YiJiPagerAdapter.destroyItem(YiJiAct.java:176)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.support.v4.view.ViewPager.populate(ViewPager.java:1036)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
06-22 23:45:50.120: E/AndroidRuntime(6217): 	at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)

   Android viewpager里面嵌套使用listview或者ExpandableList时,在移出子view时报IllegalArgumentExcept;

   这个是因为4.0系统对viewpage的兼容问题导致的,因为viewpager在移除listview或者expandableList时会调用一次listview(expandableList)的unregisterDataSetObserver方法,而listview(expandableList)本身也会调用这个方法,解决方法就是复写adapter的unregisterDataSetObserver方法,判断一下如果observer是null就不执行了:

	@Override
		public void unregisterDataSetObserver(DataSetObserver observer) {
			if(observer != null)
				super.unregisterDataSetObserver(observer);
		}

 

你可能感兴趣的:(Android,expandableList,listview,viewpager)