Java.lang.illegalstateexception: The Application Pageradapter Changed The Adapter's Contents Without Calling Pageradapter#notifydatasetchanged Android
Solution 1:
look at your code:
@Overridepublic int getItemPosition(Objectobject) {
returnPOSITION_NONE;
}
this code is use to refresh view when view change. it is also called notifyDataSetChanged()
its optional ovverride method so you can remove it.
Take a look at this answer: ViewPager PagerAdapter not updating the View
or else you can Change the FragmentStatePagerAdapter
to FragmentPagerAdapter
Solution 2:
Sometimes this error occurs.
Here is my suggestion:
In your DataResult
->getData()
return a copy of the data.
DataResult
is a singleton and holds the data. When your view gets the data, the view gets the data reference witch the DataResult
is holding. Then setData()
would change the data
reference. Here comes the IllegalStateException.
Hope it would work :)
Solution 3:
I think your DataResult
class is not necessary.
According to your comment you are getting the error while you are updating the data set. I think you are getting data from some REST API or another web service. Then assign the data you gets from the API to a temporary Array List and update that temporary array list while you are getting new data. Don't touch the mListA
variable until you finish receiving data. After complete getting data from the API assign the temporary array list you used to mListA
directly in one line.
mListA = tmpList;
Then again call
mList = mListA;
pagerAdapter.notifyDataSetChanged();
This should solve your error.
Solution 4:
try using the following way:
mList=newArrayList<Datum>();
mList.addAll(DataResult.getInstance().getData());
DataResult.getInstance().resetData();
Solution 5:
It may because you first setAdapter()
and notifyDataSetChanged
in method initUI()
;
Then, you instantiate the List<?>
data in method initData()
, the two methods in different lifetime of fragment.
It's the problem about fragment's lifecycle
Post a Comment for "Java.lang.illegalstateexception: The Application Pageradapter Changed The Adapter's Contents Without Calling Pageradapter#notifydatasetchanged Android"