public abstract boolean isViewFromObject (View view, Object object)
Determines whether a page View is associated with a specific key object as returned by instantiateItem(ViewGroup, int). This method is required for a PagerAdapter to function properly.
Parameters
view Page View to check for association with object
object Object to check for association with view
Returns
true if view is associated with the key object object
api这么写,判断view是不是和object相关,还是不大懂要干嘛?
One method of PagerAdapter is
This method declares that the return value is not necessarily a view, but can be any object. You must know that the view is added inside this method through the container, so this method does not necessarily need to return the view.
The isViewFromObject method is used to determine whether a view of the pager is related to the object returned by the instantiateItem method. If there is a correlation, what should be done? Go look at the code
ViewPager source code. If you look at the addNewItem method, you will find how to use instantiateItem. Pay attention to the mItems variable here. Then if you search for isViewFromObject, you will find that it is called by the infoForChild method, and the return value is ItemInfo. Let's take a look at the structure of ItemInfo. There is an object object in it, and this value is returned by instantiateItem.
In other words, ViewPager uses an mItems (ArrayList) to store the information (ItemInfo) of each page. When the interface is to be displayed or changes, it needs to be adjusted based on the current information of the page, but at this time it can only Search through view, so you can only traverse mItems and find the corresponding ItemInfo by comparing view and object.
It’s a bit confusing, just read the source code and you’ll understand!