I'm using a FragmentStatePagerAdapter
in order to achieve a VerticalPageAdapter
purpose, I have to create a dynamic number of the same Fragment regarding to which Button
is pressed, So, I retrieve only the specified fragment in the getItem()
method :
public Fragment getItem(int i) {
return new Center_ver();
}
And the getCount()
returns a dynamic number regarding to the pressed Button
in other fragment:
@Override
public int getCount() {
return num_of_gangs;
}
But that gave me IlligalStateException
as I'm not called notifyDataSetChanged()
, So, I added the notification to the method that I'm using to raising the number of Fragments:
public void add_gang() {
num_of_gangs ++;
notifyDataSetChanged();
}
but I also got the IlligalStateException
:
05-04 13:43:43.210: E/AndroidRuntime(1625): FATAL EXCEPTION: main
05-04 13:43:43.210: E/AndroidRuntime(1625): java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 1, found: 5 Pager id: com.automation.isolace:id/lighting_vertical_pager Pager class: class com.automation.standards.VerticalViewPager Problematic adapter: class com.automation.pageadapters.LightVerticalPageAdapter
So, I decided to add it in the getCount() method before returning the Value as follows:
@Override
public int getCount() {
notifyDataSetChanged();
return num_of_gangs ;
}
but that gave me a StackOverflowError
:
05-04 13:46:36.326: E/AndroidRuntime(1690): FATAL EXCEPTION: main
05-04 13:46:36.326: E/AndroidRuntime(1690): java.lang.StackOverflowError
05-04 13:46:36.326: E/AndroidRuntime(1690): at com.automation.standards.VerticalViewPager$PagerObserver.onChanged(VerticalViewPager.java:2717)
05-04 13:46:36.326: E/AndroidRuntime(1690): at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
05-04 13:46:36.326: E/AndroidRuntime(1690): at android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:276)